graham23s Posted February 14, 2008 Share Posted February 14, 2008 Hi Guys, In a form i have 2 inputs: <td align=\"center\"><input type=\"hidden\" name=\"pid[]\" value=\"$product_id\"><input type=\"text\" name=\"q[]\" size=\"5\" value=\"$product_qty\"> i have put them in [] to make arrays, when submitted i catch the GET like: if($_GET['action'] == 'update') { $product_id_to_update = $_POST['pid']; $quantity_to_update = $_POST['q']; foreach($quantity_to_update as $value) { // update query // $queryupdate = "UPDATE `fcp_orders` SET `qty`='$value' WHERE `product_id`='$product_id_to_update'"; echo $queryupdate; echo ("<br />"); } } which displays this when echoed out: UPDATE `fcp_orders` SET `qty`='577' WHERE `product_id`='Array' UPDATE `fcp_orders` SET `qty`='277' WHERE `product_id`='Array' UPDATE `fcp_orders` SET `qty`='377' WHERE `product_id`='Array' which is half way there i need the product_id to be the actual integers, is there anyway i can combine the foreach to include them both at all? thanks guys Graham Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 14, 2008 Share Posted February 14, 2008 A better way would be to do this in your form: <?php echo '<td align="center"><input type="text" size="5" name="pid[' . $product_id . ']" value="' . $product_qty . '">'; ?> Then you could do: <?php foreach ($_POST['pid'] as $product_id => $value) { $queryupdate = "UPDATE `fcp_orders` SET `qty`='$value' WHERE `product_id`='$product_id'"; echo $queryupdate . "<br>\n"; }?> Ken Quote Link to comment Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 <?php foreach ($_POST['pid'] as $k => $prod) { $qty = $_POST['q'][$k]; $sql = "UPDATE `fcp_orders` SET `qty`= $qty WHERE `product_id`='$prod'"; mysql_query($sql); } Quote Link to comment Share on other sites More sharing options...
graham23s Posted February 14, 2008 Author Share Posted February 14, 2008 Thanks a ton guys i'm sorted. Graham 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.