cheechm Posted May 10, 2008 Share Posted May 10, 2008 I have three select fields. Say someone chooses the number "1" on one of them, "2" on the other and "3" on the other. Each of those values will also be paired with a field id. EG: ID----Select Value 01----1 02----2 03----3 the user might change it to something like this: ID----Select Value 01----2 02----3 03----1 I need to know how to post that data (I know to use hidden field with the id) but I don't know how to insert multiple things. EG: 'UPDATE site SET select_value = '. $select_value .' WHERE id = ' .$id; But how do I do that for all the options at once. Thanks Quote Link to comment Share on other sites More sharing options...
phorcon3 Posted May 10, 2008 Share Posted May 10, 2008 <?php mysql_query("UPDATE `table` SET `field1` = '$_POST[value1]', `field2` = '$_POST[value2]', `field3` = '$_POST[value3]' WHERE `id` = '$id'"); ?> Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 10, 2008 Author Share Posted May 10, 2008 It is this code: <form id="acp_menu" method="post" action="./index.php" name="menu"> <input type="hidden" name="action" value="save" /> <input type="hidden" name="title" value="Home" /> <input type="hidden" name="link" value="index.php?id=1" /> <input type="hidden" name="id" value="1" /> <input type="hidden" name="action" value="save" /> <input type="hidden" name="title" value="Test" /> <input type="hidden" name="link" value="Test" /> <input type="hidden" name="id" value="9" /> <input type="hidden" name="action" value="save" /> <input type="hidden" name="title" value="Test" /> <input type="hidden" name="link" value="Tsss" /> <input type="hidden" name="id" value="11" /> </form> How do I update the data from that into one table all at once? Thanks Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 10, 2008 Author Share Posted May 10, 2008 Apparently I need to make it an array? Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 10, 2008 Author Share Posted May 10, 2008 Bumpy.... Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 <?php mysql_query("UPDATE `table` SET `field1` = '{$_POST[value1]}', `field2` = '{$_POST[value2]}', `field3` = '{$_POST[value3]}' WHERE `id` = '$id'"); ?> Quote Link to comment Share on other sites More sharing options...
crtreedude Posted May 10, 2008 Share Posted May 10, 2008 If each of your sets represents a row, you don´t. And you aren't inserting, you are updating. Why do you wish to do it as a single statement? If you are concerned about data integrity while updating each row, wrap it with a transaction statement, which will make it atomic. (i.e. done as a unit, not as separate transactions) I would assume that your ID is the primary key for each row. Hope this helps. Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 11, 2008 Author Share Posted May 11, 2008 ------ id (Primary Key) --- title --- link --- order ------ Literally on the submit of this form <input type="hidden" name="title" value="Home" /> <input type="hidden" name="link" value="index.php?id=1" /> <input type="hidden" name="id" value="1" /> <input type="hidden" name="title" value="Test" /> <input type="hidden" name="link" value="Test" /> <input type="hidden" name="id" value="9" /> <input type="hidden" name="title" value="Test" /> <input type="hidden" name="link" value="Tsss" /> <input type="hidden" name="id" value="11" /> <input type="hidden" name="action" value="save" /> every single on of those values needs to be inputted where the id is whatever is posted. So literally this@ ------ [row]id (Primary Key) | 1 | 9 | 11 --- [row]title | Home | Test | Test --- [row]link | index.php?id=1 | Test | Tsss --- [row]order | NULL | NULL | NULL ------ So how do I insert multiple values at the same time? Thanks Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 11, 2008 Author Share Posted May 11, 2008 Bumpity. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 !!!!!!!!!!!!!!!!!!!!! <?php mysql_query("UPDATE `table` SET `field1` = '{$_POST[value1]}', `field2` = '{$_POST[value2]}', `field3` = '{$_POST[value3]}' WHERE `id` = '$id'"); ?> ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 13, 2008 Author Share Posted May 13, 2008 That doesn't work. Quote Link to comment Share on other sites More sharing options...
craygo Posted May 13, 2008 Share Posted May 13, 2008 Try this out <?php $count = count($_POST['action']); for($i=0; $i<$count; $i++){ $sql = "UPDATE `table` SET `title` = {$_POST['title'][$i]}, `link` = {$_POST['link'][$i]} WHERE `id` = {$_POST['id'][$i]}"; echo $sql."<br />"; } ?> Ray Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 13, 2008 Author Share Posted May 13, 2008 Neither does that unluckily. Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 13, 2008 Author Share Posted May 13, 2008 Wait. Forgot to post as an array. All fixed now. Thanks again craygo! 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.