I suspect there is a problem with the $update_code variable. Not sure, but I need some help.
Expand|Select|Wrap|Line Numbers
- <?php
- require 'common.php';
- //session_start();
- session.auto_start;
- $_SESSION['procFlag'] =1;
- $code = $_REQUEST['code'];
- $num = $_REQUEST['num'];
- $update_code= $_REQUEST['update_code'];
- if($_SESSION['procFlag'] ==1)
- {
- // adds number of items ordered to the cart
- if ($code) $_SESSION['cart'][$code] +=$num;
- {
- $_SESSION['ProcFlag']++;
- }
- //removes all items ordered from the cart
- if ($update_code) $_SESSION['cart'][$update_code]--;
- }
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
- <title></title>
- <link rel="stylesheet" type="text/css" href="cart.css">
- </head>
- <body>
- <h1></h1>
- <div class="goods-list">
- <table>
- <tr><th align="left">Image<br /></th><th align="left">Product Name<br /></th><th align="left">Unit Cost<br /></th><th>Quantity<br /></th><th>Total<br /></th></tr>
- <?php
- $sum = 0;
- foreach ($_SESSION['cart'] as $code =>$num)
- {
- if($num <=0 ) {continue;}
- //selects goods from database
- $sql = "SELECT * FROM goods WHERE code=" .$code;
- $mysql->query($sql);
- $row = $mysql->fetch();
- // quantity ordered x unit price
- $ss = $num * $row['price'];
- // calculates total cost of all goods
- $sum += $ss;
- //echo's the pic file in the database
- echo "<tr><td>";
- $pic = $row['pic'];
- $host = get_host();
- if (strlen($pic)>0)
- {
- $disp_pic = "http://$host/img/" .$pic;
- }
- echo "<img src=\"$disp_pic\" border=\"0\" width=\"60px\" height=\"60px\"></td>";
- echo "<td class=\"gname\">{$row['name']}</td>
- <td class=\"gtanka\">{$row['price']}</td>
- <td class=\"gsuuryou\">{$num}</td>
- <td class=\"gsyoukei\">{$ss}</td>";
- echo '<td class=\"gsakujyo\" align=\"left\" ><form method="post" action="cart.php?<?=$code?>">';
- echo '<input type="hidden" name="update_code[]" value="' . $row['code'] . '">';
- echo ' <input type="submit" value="remove"></form></td></tr>';
- echo "<tr><td colspan='2'> </td>
- <td class=\"ggoukei_title\"></td>
- <td class=\"ggoukei\">{$sum}</td></tr>\n";
- }
- ?>
- <?php
- if (isset($_SESSION['cart']))
- {
- $_SESSION['cart']=$row['name']++;
- }
- else
- {
- $_SESSION['cart']="cookies are not set";
- }
- echo $_SESSION['cart'];
- ?>
- </table>
- <br><a href="index2.php?code=<?=$row['code']?>">CONTINUE SHOPPING </a>
- <br><a href="cart_empty.php">CHECKOUT </a>
- </div>
- </body>
- </html>