Advertisement
Guest User

Untitled

a guest
Jan 19th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. <?php
  2. include("includes/db.php");
  3. include("includes/functions.php");
  4.  
  5. if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
  6. remove_product($_REQUEST['pid']);
  7. }
  8. else if($_REQUEST['command']=='clear'){
  9. unset($_SESSION['cart']);
  10. }
  11. else if($_REQUEST['command']=='update'){
  12. $max=count($_SESSION['cart']);
  13. for($i=0;$i<$max;$i++){
  14. $pid=$_SESSION['cart'][$i]['productid'];
  15. $q=intval($_REQUEST['product'.$pid]);
  16. if($q>0 && $q<=999){
  17. $_SESSION['cart'][$i]['qty']=$q;
  18. }
  19. else{
  20. $msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
  21. }
  22. }
  23. }
  24.  
  25. ?>
  26. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  27. <html xmlns="http://www.w3.org/1999/xhtml">
  28. <head>
  29. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  30. <title>Shopping Cart</title>
  31. <script language="javascript">
  32. function del(pid){
  33. if(confirm('Do you really mean to delete this item')){
  34. document.form1.pid.value=pid;
  35. document.form1.command.value='delete';
  36. document.form1.submit();
  37. }
  38. }
  39. function clear_cart(){
  40. if(confirm('This will empty your shopping cart, continue?')){
  41. document.form1.command.value='clear';
  42. document.form1.submit();
  43. }
  44. }
  45. function update_cart(){
  46. document.form1.command.value='update';
  47. document.form1.submit();
  48. }
  49.  
  50.  
  51. </script>
  52. </head>
  53.  
  54. <body>
  55. <form name="form1" method="post">
  56. <input type="hidden" name="pid" />
  57. <input type="hidden" name="command" />
  58. <div style="margin:0px auto; width:600px;" >
  59. <div style="padding-bottom:10px">
  60. <h1 align="center">Your Shopping Cart</h1>
  61. <input type="button" value="Continue Shopping" onclick="window.location='products.php'" />
  62. </div>
  63. <div style="color:#F00"><?=$msg?></div>
  64. <table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
  65. <?php
  66. if(is_array($_SESSION['cart'])){
  67. echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td>Serial</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</td></tr>';
  68. $max=count($_SESSION['cart']);
  69. for($i=0;$i<$max;$i++){
  70. $pid=$_SESSION['cart'][$i]['productid'];
  71. $q=$_SESSION['cart'][$i]['qty'];
  72. $pname=get_product_name($pid);
  73. if($q==0) continue;
  74. ?>
  75. <tr bgcolor="#FFFFFF"><td><?=$i+1?></td><td><?=$pname?></td>
  76. <td>$ <?=get_price($pid)?></td>
  77. <td><input type="text" name="product<?=$pid?>" value="<?=$q?>" maxlength="3" size="2" /></td>
  78. <td>$ <?=get_price($pid)*$q?></td>
  79. <td><a href="javascript:del(<?=$pid?>)">Remove</a></td></tr>
  80. <?php
  81. }
  82. ?>
  83. <tr><td><b>Order Total: $<?=get_order_total()?></b></td><td colspan="5" align="right"><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"><input type="button" value="Place Order" onclick="window.location='billing.php'"></td></tr>
  84. <?php
  85. }
  86. else{
  87. echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
  88. }
  89. ?>
  90. </table>
  91. </div>
  92. </form>
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement