basic-php-15-checkout3.php / php
<?php session_start(); //connect to the database - either include a connection variable file //or type the following lines: //Let's make the variables easy to access in our queries firstname = lastname = firstname = add1 = add2 = city = state = zip = phone = fax = email = shipfirst = shiplast = shipadd1 = shipadd2 = shipcity = shipstate = shipzip = shipstate = shipphone = shipemail = total = sessid = session_id(); //1) Assign Customer Number to new Customer, or find existing customer number query = "SELECT * FROM customers WHERE (customers_firstname = 'lastname' AND customers_add1 = 'add2' AND customers_city = 'results = mysql_query(rows = mysql_num_rows(rows < 1) { //assign new custnum firstname', 'add1', 'city', 'zip', 'fax', 'insert = mysql_query(custid = mysql_insert_id(); } //If custid exists, we want to make it equal to custnum //Otherwise we will use the existing custnum if (customers_custnum = //2) Insert Info into ordermain //determine shipping costs based on order total (25% of total) shipping = query3 = "INSERT INTO ordermain ( ordermain_orderdate, ordermain_custnum, ordermain_subtotal,ordermain_shipping, ordermain_shipfirst, ordermain_shiplast, ordermain_shipadd1, ordermain_shipadd2, ordermain_shipcity, ordermain_shipstate, ordermain_shipzip, ordermain_shipphone, ordermain_shipemail) VALUES ( 'customers_custnum', 'shipping' 'shiplast', 'shipadd2', 'shipstate', 'shipphone', 'insert2 = mysql_query(orderid = mysql_insert_id(); //3) Insert Info into orderdet //find the correct cart information being temporarily stored sessid'"; query) or (mysql_error()); //put the data into the database one row at a time while (results)) { extract(query4 = "INSERT INTO orderdet ( orderdet_ordernum, orderdet_qty, orderdet_prodnum) VALUES ( 'carttemp_quan', 'insert4 = mysql_query(//4)delete from temporary table query = "DELETE FROM carttemp WHERE carttemp_sess='delete = mysql_query(//5)email confirmations to us and to the customer /* recipients */ to = "<" . /* subject */ subject = "Order Confirmation"; /* message */ /* top of message */ <html> <head> <title>Order Confirmation</title> </head> <body> Here is a recap of your order:<br><br> Order date: "; message .= message .= " <br> Order Number: "; orderid; <table width=\"50%\" border=\"0\"> <tr> <td> <p>Bill to:<br>"; message .= message .= " "; lastname; <br>"; message .= message .= "<br>"; if (message .= <br>"; } message .= state . " " . message .= "</p></td> <td> <p>Ship to:<br>"; shipfirst . " " . message .= "<br>"; shipadd1 . "<br>"; if (message .= <br>"; } message .= shipstate . " " . message .= "</p> </td> </tr> </table> <hr width=\"250px\" align=\"left\"> <table cellpadding=\"5\">"; //grab the contents of the order and insert them //into the message field orderid'"; query) or die (mysql_query()); while (results)) { extract(prod = "SELECT * FROM products WHERE products_prodnum = 'prod2 = mysql_query(prod3 = mysql_fetch_array(prod3); <tr><td>"; message .= message .= "</td>"; <td>"; message .= message .= "</td>"; <td align=\"right\">"; message .= message .= "</td>"; <td align=\"right\">"; //get extended price extprice = number_format(orderdet_qty, 2); extprice; </td>"; message .= "</tr>"; } <tr> <td colspan=\"3\" align=\"right\"> Your total before shipping is: </td> <td align=\"right\">"; message .= number_format(message .= " </td> </tr> <tr> <td colspan=\"3\" align=\"right\"> Shipping Costs: </td> <td align=\"right\">"; shipping, 2); </td> </tr> <tr> <td colspan=\"3\" align=\"right\"> Your final total is: </td> <td align=\"right\"> "; message .= number_format((shipping), 2); </td> </tr> </table> </body> </html>"; /* headers */ headers = "MIME-Version: 1.0\r\n"; headers .= "From: <storeemail@email.com>\r\n"; <storeemail@email.com>\r\n"; headers .= "X-Mailer: PHP / ".phpversion()."\r\n"; /* mail it */ mail(subject, headers); //6)show them their order & give them an order number echo "Step 1 - Please Enter Billing and Shipping Information<br>"; echo "Step 2 - Please Verify Accuracy and Make Any Necessary Changes<br>"; echo "<strong>Step 3 - Order Confirmation and Receipt</strong><br><br>"; echo
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.