PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Im making a form and in the form i have a mysql query that makes text fields with a specific name for each. when you hit submit i need it to update the database with the new quantity (what was in the textbox).
my problem is i need a way to count the amount of textboxes that were submited with the form. I also need to be able to send a hidden field with each textbox so i can have the itemID and the quantity for that itemID.
for ($i=0; $i</*amount of textboxes submited whith the form*/; $i++){
$qry = mysql_query("UPDATE cart SET qty="/*named textbox*/" WHERE itemID="/*itemID going with the named textbox*/"");
}
i know this is a bit confusing, sorry i really cant word this any better because im real confused as to how to do this.
you could iterate through the posted data using isset() until you hit a false.. or, you could name them such that they create an array for php to hand right to you.
one thing i've noticed from your 3 lines of codes is that it has to do as many querries as your posted data, and that is not a good idea. You can update your table in 1 single query.
feyd wrote:base the name off the itemID in some fashion..
the itemID is preset and i wanna pass it through a hidden field but i need to link the quantity field and the hidden field together even though there will be many hidden and quantity fields in the 1 form. heres some code maybe this will make it clearer?
<form action="view_cart.php?action=update_qty" method="post">
$itm_qty = mysql_query("SELECT * FROM cart WHERE cartID='$cartID' AND itemID='$itemID'");
while ($row_qty = mysql_fetch_assoc($itm_qty)){
echo '<td>
<input type="text" name="'.$z++.'" value="'.$row_qty['qty'].'" size="2">
//i need a way to have the $itemID in a hidden field that i can link to the $z++ thing
</td>
';
}
echo '
<input type="submit" name="new_qty_s" value="Change Quantity">
</form>';
keep in mind that this is inside of another loop and each time the other loop goes through $itemID changes
lol sorry but! a name that will automatically create a array or somtin i can make one out of like a number autoincrementing like i have $z made? that still dosnt help me link the $z to whatever i define the hidden field holding the itemID for that $z? please elaborate