html - Make checkout in php and insert order in mysql -
i build m storage system , , built shopping cart , want make checkout , insert order items,customer name , others information in orders items confirmed because order status waiting , shopping cart page code
<?php session_start(); ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="php shopping cart using sessions" /> <meta name="keywords" content="shopping cart tutorial, shopping cart, php, sessions" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" media="all" href="/style/style.css" type="text/css" /> <link href="prdtable.css" rel="stylesheet" type="text/css" /> <title>shopping cart</title> <?php include "connect.php"; error_reporting(e_all ^ e_notice) ?> </head> <body> <form id='login' action='login.php' method='post' accept-charset='utf-8'> <input type='hidden' name='submitted' id='submitted' value='1'/> <div style="width:550px;position:absolute; left: 436px; top: 74px;" > <label for='username' style="color:#1e4e9a;font-family:impact, haettenschweiler, 'arial narrow bold', sans-serif" >userame:</label> <input id="sign" type='text' name='username' maxlength="50" /> <label for='password'style="color:#1e4e9a;font-family:impact, haettenschweiler, 'arial narrow bold', sans-serif" >password:</label> <input id="sign" type='password' name='password' maxlength="50" /> <input type='submit' name='submit' value='submit' /> </div> </form><?php require('header.php'); ?> <?php $product_id = null; $action = ''; $cartlist = ''; if (isset($_get['prdid'])) $product_id = $_get['prdid']; if (isset($_get['action'])) $action = $_get['action']; $total = 0; if($product_id && !productexists($product_id)) { die("error. product doesn't exist"); } switch($action) { case "add": $_session['cart'][$product_id]++; break; case "remove": $_session['cart'][$product_id]--; if($_session['cart'][$product_id] == 0) unset($_session['cart'][$product_id]); //if break; case "empty": unset($_session['cart']); break; } ?> <?php if($_session['cart']) { foreach($_session['cart'] $product_id => $quantity) { $sql ="select prdname, prddesc, prdprice product prdid = $product_id"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { list($name, $description, $price) = mysql_fetch_row($result); $line_cost = $price * $quantity; $total = $total + $line_cost; $cartlist .= '<tr> <td><img height="50px" width="50px" src="products/' . $product_id . '.jpg"/></td> <td>' . $name . '</td> <td>' . $price . ' $ </td> <td>'. $quantity.'</td> <td>'.$line_cost.'</td> <td><a href=shopping_cart.php?action=remove&prdid='.$product_id.'>remove</a></td> </tr> '; } } }else{ echo "<center><font color='#000066' size='5'>you have no items in shopping cart .</font><a href='index.php' >start shopping</a></center>"; } function productexists($product_id) { $sql = "select * product prdid = $product_id "; return mysql_num_rows(mysql_query($sql)) > 0; } ?> <div style="position:absolute; left:200px;top:200px"> <table id="prdtable"> <tr> <th>item image</th> <th>name</th> <th>price</th> <th>qty</th> <th>amount</th> <th>options</th> </tr> <?php echo $cartlist;?> <tr><td colspan="2" align="right" style="color:#e71818"><strong>total price</strong></td> <td align="right" style="color:#e71818"> <?php echo $total; ?> $</td></tr> </table> <br/> <center><a href="checkout.php" ><img height="34px" width="80px" src="checkout.png" /></a></center> </div> <div id='cssmenu' style="position:absolute; left: -13px; top: 187px;" > <?php require('menu.php'); ?> </div> </body> </html>
Comments
Post a Comment