callisto11 Posted July 30, 2008 Share Posted July 30, 2008 Hi everyone, Im finding it hard to make this form work (i've hightlight out the problem in green) what I want is, for a user to be able to update the quantity field of the item they insert into the shopping. So once they have inserted the new amount, they should be able to press update quantity button and it changes it. Thank you Calliso (Im very new to php ) <form action="update_item" method="get"> <input type="hidden" name="action" value="update_item" /> <table width="40%" border="1" bordercolor="black" bgcolor=""> <tr> <th width="5%"> <span class="style7">STYLE NUMBER</span></th> <th width="6%"> <span class="style7">DETAILS</span></th> <th width="6%"> <span class="style8">QUANTITY</span></th> <th width="7%"> <span class="style8">SIZE </span></th> <th width="7%"> <span class="style8">PRICE (per cartoon) </span></th> <th width="8%"> -</th> <?php foreach ($_SESSION['cart'] as $key => $general_cartoon) { ?> </tr> <tr> <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['cartoon_id']; ?></span></td> <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['title']; ?></span></td> <td><input type="text" size="2" name="quantity" value="<?php echo $_SESSION['cart'][$key] ['quantity']; ?>"/></td> <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['size'];?></span></td> <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['fee'];?></span></td> <?php $quantity =$_SESSION['cart'][$key]['quantity'];?> <td><a href="removefromcart.php?cartoon_id=<?php echo $_SESSION['cart'][$key]['cartoon_id'];?>&location=<?php echo $_SERVER['PHP_SELF'];?>">[REMOVE]</a></td> </tr> <?php }?> </table> <p> <?php } else { ?> No cartoon chosen yet <?php } ?> </p> <p> </p> <input name="update" type="submit" value="UPDATE QUANTITIES" title=" Updates the quantities of cartoons in the shopping cart"/> </form> Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted July 30, 2008 Share Posted July 30, 2008 Is update_item suppose to be update_item.php? Also, in update_item file, are you using a switch condition to control the action? If so, I would do this: <form action="update_item.php?action=Update Item" method="post"> Then on the update_item page, do this: if(array_key_exists('action', $_GET))// check and grab the variable from the URL { $action = $_GET['action']; } if(array_key_exists('quantity', $_POST)) { $qty = $_POST['quantity']; } Then the switch would be: switch($action) { case 'Update Item': Your logic goes here such as the UPDATE mysql code.... break; } Hope this helps you out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.