Friday, September 12, 2014

Simple Adding and Inserting image with PHP

These are the codes in our Administration area, credits to sourcecodester.com.

-> please make sure you have a connection with the database:
<?php
error_reporting(0);
session_start();
include("dbconnect.php");
$action = $_REQUEST['action']; 
?>
1. Let's start with ADDING along with INSERTING IMAGE form:
elseif($action=="YOURACTION"){
echo "<CENTER><form action='admin.php' method='post' enctype='multipart/form-data'>";
echo "<table>";
echo "<tr><td colspan=2 align=center>  Add Profile </td></tr>";
echo "<tr><td>  Firstname: </td><td><input type=text name=denfname size=30></td></tr>";
echo "<tr><td>  Lastname: </td><td><input type=text name=denlname size=30></td></tr>";
echo "<tr><td>  Address: </td><td><input type=text name=denaddress size=30></td></tr>";
echo "<tr><td> Gender:<td><select name=dengen><option name=dengen> Male";
echo "<option name=dengen> Female"; echo "</select></td>";
echo "<tr><td> Add picture: </td><td><input type=file name=logo size=20></td></tr>";
echo "<tr><td align=center colspan=2><input type=submit name=submit value='add dentist'></td></tr>";
echo "<input type=hidden name=action value=YOUR_ACTION>";
echo "</form>";
echo "</table>";
}
*then your query for YOUR_ACTION
elseif($action=="YOUR_ACTION"){
if ($_FILES['logo']['name'] != "") { 
$imageInfo = getimagesize($_FILES['logo']['tmp_name']); // get image size
$width = $imageInfo[0]; // image width
$height = $imageInfo[1];  // image height

if($height > 2000 || $width > 2000){
echo "<script> alert('Image is to big! Try to resize the picture!') </script>";
exit;
} // check size 

$newimg1 = date("YmdHis").".jpg";  // set name for new image
$newimg2 = date("YmdHis").".pdf"; // set name for pdf if is necesary

if(stristr($_SERVER['OS'],"win")){
$path = "prodimg/";
} // determin path of image folder
elseif(stristr($_SERVER['OS'],"linux")){
$path = str_replace("admin.php","",$_SERVER['SCRIPT_FILENAME']) . "prodimg/";
else {
$path = "prodimg/";
}

move_uploaded_file ( $_FILES['logo']['tmp_name'], $path . $newimg1  );
}  // copy image in image folder
else{
$newimg1="pc.gif"; 
} // if is not posible than set image name as pc.gif

$denfname = $_POST['denfname'];
$denlname = $_POST['denlname'];
$denaddress = $_POST['denaddress'];
$dengen = $_POST['dengen'];
$res2 = mysql_query("insert into dentists(denfname,denlname,denaddress,dengen,denpicture) 
values('$denfname','$denlname','$denaddress','$dengen','$newimg1')");

echo "<script>location.replace('admin.php?action=showalldentists')</script>";
}


 




 


Read, Write and Create Excel documents in PHP - Spreadsheet engine

Microsoft office documents is very useful to many workers, now here is PHPExcel,to make your work easier and so that you can save time, PHPExcel has many types of format you can select.Below I will show you a sample of code so that you will have knowledge on applying your codes with PHPExcel, I've used 10autofilter here because I find it fits our work and hopefully also to you.

->Download PHPExcel here

1. To start I will show you the data that we will generate on excel.


*Administration area codes credits to sourcecodester.com
and the excecuted file 


2. Now below will be the codes from 10autofilter, please make sure that you have a connection to your database.

<?php
error_reporting(0);
session_start();
 include("dbconnect.php");
/**
 * PHPExcel
 *
 * Copyright (C) 2006 - 2014 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel
 * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
 * @version    1.8.0, 2014-03-02
 */

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('Europe/London');

/** Include PHPExcel */
require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';

// Create new PHPExcel object
echo date('H:i:s').' Create new PHPExcel object'.EOL;
$objPHPExcel = new PHPExcel();


// Set document properties
echo date('H:i:s').' Set document properties'.EOL;
$objPHPExcel->getProperties()->setCreator('Maarten Balliauw')
->setLastModifiedBy('Maarten Balliauw')
->setTitle('PHPExcel Test Document')
->setSubject('PHPExcel Test Document')
->setDescription('Test document for PHPExcel, generated using PHP classes.')
->setKeywords('office PHPExcel php')
->setCategory('Test result file');

// Create the worksheet
echo date('H:i:s').' Add data'.EOL;
$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Year Assisted')
                              ->setCellValue('B1', 'Project Code')
 ->setCellValue('C1', 'Project Proponent')
 ->setCellValue('D1', 'Project Title')
 ->setCellValue('E1', 'Sector')
 ->setCellValue('F1', 'Contact Person')
 ->setCellValue('G1', 'Project Location')
 ->setCellValue('H1', 'Setup Investment')
 ->setCellValue('I1', 'Beneficiary Investment')
 ->setCellValue('J1', 'Date Approved RPMO')
  ->setCellValue('K1', 'Date Received RPMO')
 ->setCellValue('L1', 'Date of RTEC review')
 ->setCellValue('M1', 'Date endorsed to NPMO')
 ->setCellValue('N1', 'Date approved NPMO')
 ->setCellValue('O1', 'Remarks');
                            
/** edit your query here */  
$query = "select * from appointment_detail,services where (services.serviceid = appointment_detail.serviceid) and `status`='on progress' ORDER by yearassistancereceived";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($result);
for($x=0; $x<$row; $x++)
{
$servicename = mysql_result($result,$x,"servicename");
$projectcode= mysql_result($result,$x,"projectcode");
$projecttitle = mysql_result($result,$x,"projecttitle");
$update = mysql_result($result,$x,"update");
$remarks = mysql_result($result,$x,"projectstatus");
$projectlocation = mysql_result($result,$x,"limitt");
$yearassistancereceived = mysql_result($result,$x,"yearassistancereceived");
$setupinvestment = mysql_result($result,$x,"setupinvestment");
$beneficiaryinvestment = mysql_result($result,$x,"beneficiaryinvestment");
$confname = mysql_result($result,$x,"charge");
$conmiddlename = mysql_result($result,$x,"contactmiddlename");
$conlname = mysql_result($result,$x,"contactlastname");
$contactperson = $confname." ".$conmiddlename." ".$conlname;
$update = mysql_result($result,$x,"update");
$sector = mysql_result($result,$x,"sector");
$projectstatus = mysql_result($result,$x,"projectstatus");
$expectedoutput = mysql_result($result,$x,"expectedoutput");
$datereceivedbyrpmo  = mysql_result($result,$x,"datereceivedbyrpmo");
$dateapprovednpmo = mysql_result($result,$x,"dateapprovednpmo");
$dateendorsedtonpmo = mysql_result($result,$x,"dateendorsedtonpmo");
$dateapprovedatrpmolevel = mysql_result($result,$x,"dateapprovedatrpmolevel");
$dateofrtecreview = mysql_result($result,$x,"dateofrtecreview");
    $dataArray = array(
        array(
$yearassistancereceived,
            $projectcode,
            $servicename,
$projecttitle,
$sector,
$contactperson,
$projectlocation,
$setupinvestment,
$beneficiaryinvestment,
$dateapprovedatrpmolevel,
$datereceivedbyrpmo,
$dateofrtecreview,
$dateendorsedtonpmo,
$dateapprovednpmo,
$remarks
        )
    );

    $objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A'.($x+2));
}

// Set title row bold
echo date('H:i:s').' Set title row bold'.EOL;
$objPHPExcel->getActiveSheet()->getStyle('A1:O1')->getFont()->setBold(true);

// Set autofilter
echo date('H:i:s').' Set autofilter'.EOL;
// Always include the complete filter range!
// Excel does support setting only the caption
// row, but that's not a best practise...
$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension());

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace(__FILE__, 'C:/DOSTX On Progress Projects.xlsx', __FILE__));

$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;

echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;


// Save Excel 95 file
echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
ECHO $filename= str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;


// Echo memory peak usage
echo date('H:i:s').' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB'.EOL;

// Echo done
echo date('H:i:s').' Done writing files'.EOL;


  echo "<script>alert('File saved at drive C')</script>";
?>

  /** Happy coding! :) */



Tuesday, September 9, 2014

PHP Simple hotel reservation with Datepicker, Sandbox Paypal transaction/Ipn setup with PHP

This is a simple reservation with php.This is hosted for free, you can visit here for demo. Codes credits to sourcecodester.com hotel reservation tamera.

->Below is instructions to setup your sandbox store.

->Files and database in downloadable link below.

Features:

*for Administration area you just add  /admin_index.php with user: admin pass: admin

*for Cashier area you just add   /admin_index.php user:argie pass:argie

*after transaction send details to email

*modify by random confirmation number send to payer on email

*cancel  by random confirmation number send to payer on email

*also upon reservation, random numbers are generated on code to avoid spam.

-> The test store is my sandbox account you can change it if you already have sandbox and you need to register for sandbox account on paypal so that you can purchase.

 1.So this is index.php.PLEASE better if you see image and read so you understand the website better.

- now first we check if date is available the user will also select on dropdown on how many adults and children, adults are up to 3 and child up to 2.



 2. after you select date you will reserve here on testing.php enter number of rooms then click reserve


*if it is not available then you cannot reserve, you will have to select another date for your reservation

*you will enter number of rooms, the more the rooms, and the more the days, of course the higher the user  pay.Formulas on code you can change the price anyway this are all tests.

3. After date and rooms are available, you will have to enter your correct information.

-> If you the user have done reservation before, you only have to enter your email and password on the top,see the image.

->  If not it is like you register below, after all details are entered correctly,click confirm.


4.Now the user can see all the reservation details here.


5.After that we will proceed to paypal's test site, this is sandbox.paypal.com.


*Good Luck on your projects! :)

SETTING UP PAYPAL IPN

*take note when you edit the codes at payment.php this is very important very important


-> login to sandbox.paypal.com, to setup your merchant account below the profile you will click on *my selling tools 

-> then you can see *Instant Payment notification then click *update


*Done!

/** Happy Coding! :) */

download the codes here







Monday, September 8, 2014

A guide to hosting your website online for free

This is for beginners hopefully this helps, it is important when you are planning to host online,
* there are lots of free hosting services online, you can search on google.
* i find hostinger easy yo understand, and this is what i used to our project.
in this tutorial this is hostinger:
Free Web Hosting

1. You can login with facebook/google here or create an account.


2.Now that you have login you can add domain here. *note: you can add domain once every 24 hours.




3. *then your database :)

*if you don't have database yet, you can create on MySQL Databases
then your username and password.

*when you already have a database, you can click on it then phpMyAdmin.


then this

*import. :)

4.if you already have your domain and your database, upload your files here, you can choose either file manager 1 or 2.


*make sure that you have a connection to your files and database before you upload, but it's a big problem though, you can edit your files if you already uploaded it, but you can save time;

* ive used file manager 2 here, upload your files on public_html.


*hope this help :)








Powered By Blogger

Translate