Introduction to php Chapter 1 ACSG 550
What we will be doing… Developing full-service websites with – dynamic content – support for user interaction – client and server-side processing – underlying databases We are using php and mysql
php A scripting language that supports server-side processing It’s a full language in its own right – Variables – Control structures – Objects We embed it into our html pages – Dynamic content – Form processing – Database processing
Where is php? On our web servers – csmaster – cs1 You can also download it from and configure it for use on your own computer In class for now, we’ll use csmaster
Example files freight.html freight.php orderform.html processorder.php
html forms Item Quantity Tires Oil Spark Plugs How did you find Bob's? I'm a regular customer TV advertising Phone directory Word of mouth orderform.html
processororder.php – Part 1 <?php // create short variable names $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $find = $_POST['find']; ?>
processororder.php – Part 2 Bob's Auto Parts - Order Results Bob's Auto Parts Order Results
processororder.php – Part 3 <?php echo ' Order processed at '; echo date('H:i, jS F'); echo ' '; echo ' Your order is as follows: '; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo 'Items ordered: '.$totalqty.' '; if( $totalqty == 0) { echo 'You did not order anything on the previous page! '; } else { if ( $tireqty>0 ) echo $tireqty.' tires '; if ( $oilqty>0 ) echo $oilqty.' bottles of oil '; if ( $sparkqty>0 ) echo $sparkqty.' spark plugs '; }
processororder.php – Part 4 $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; echo 'Subtotal: $'.number_format($totalamount,2).' '; $taxrate = 0.10; // local sales tax is 10% $totalamount = $totalamount * (1 + $taxrate); echo 'Total including tax: $'.number_format($totalamount,2).' '; if($find == 'a') echo ' Regular customer. '; elseif($find == 'b') echo ' Customer referred by TV advert. '; elseif($find == 'c') echo ' Customer referred by phone directory. '; elseif($find == 'd') echo ' Customer referred by word of mouth. '; else echo ' We do not know how this customer found us. '; ?>
freight.php Distance Cost <? $distance = 50; while ($distance <= 250 ) { echo " \n $distance \n"; echo " ". $distance / 5 " \n \n"; $distance += 50; } ?>
Assignment Lab 1 hand-out HW – read Chapter 1 Next week’s class is online – Check that you can access Blackboard – Assignments will be available in Blackboard starting Friday The topic of these assignments is the fundamentals of php, as introduced in Chapter 1