severndigital Posted February 25, 2007 Share Posted February 25, 2007 I am trying to update quantities for items in a shopping cart that are being added to the form via a while loop. see below. I know I can be simplifying my Db queries, but that is not the focus of my question. <? //this is essentially what is happening. //first start the table and form echo ' <form name="scartform" method="post" action="' . $_SERVER['PHP_SELF'] . '"> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="scartborder"> <tr> <td class="scart_headers">Item</td> <td class="scart_headers">Desc.</td> <td class="scart_headers">Qty</td> <td class="scart_headers">Per Piece </td> <td class="scart_headers">Total</td> </tr> <tr> <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td> <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td> <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td> <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td> <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td> </tr>'; //now loop the products into the table $sql = "SELECT * FROM fnlproducts WHERE dealerid='$dealerid'"; $getcontents = mysql_query($sql); while($row = mysql_fetch_array($getcontents)){ $scid = $row['scid']; $pid = $row['pid']; $qty = $row['qty']; //get some information about the product. $getpinfo = mysql_query("SELECT p_name,p_distrip,p_matrix,p_altprice FROM products WHERE pid='$pid'"); $prow = mysql_fetch_array($getpinfo); $item = $prow['p_name']; $distrip = $prow['p_distrip']; $price = $prow['p_altprice']; $tprice = $qty * $price; $tprice = money_format('%i',$tprice); $total_price = $tprice + $total_price; echo '<tr> <td class="scartborder"><span class="scitem">' . $item . '</span></td> <td class="scartborder"><span class="scitem">' . $distrip . '</td> <td class="scartborder"><span class="scitem"> <!-- ####This is the quantity form field. --> <input name="quantity-' . $scid .'" type="text" id="thisisid" size="5" maxlength="3" value="' . $qty . '"></td> <! -- ####End quantity form field --> <td class="scartborder"><span class="scitem">' . $price . '</td> <td class="scartborder"><span class="scitem">' . $tprice . '</td> </tr>'; }// end while loop. My question is when i submit the new quantites, how to post them? I can't seem to figure this out, because I have no way of knowing what the name of the field will be since I won't know beforehand what the $scid of the item will be. I know the post would be something like this $newquantity = $_POST['nameofqtyfield']; but again, i don't know how to post a field I won't know the name of ahead of time. Any help would be really great. even it means re-doing the query from the ground up. thanks in advance. Chris Quote Link to comment Share on other sites More sharing options...
Barand Posted February 25, 2007 Share Posted February 25, 2007 Use "<input name=quantity[$scid] ...... >" Then when you process the submitted data foreach ($_POST['quantity'] as $scid => $qty) { // update using $scid and $qty } Quote Link to comment Share on other sites More sharing options...
severndigital Posted February 25, 2007 Author Share Posted February 25, 2007 thank you, thank you, thank you. I know it simple now, but I have been stuck on this for 3 days. thanks again, chris 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.