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 Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/ 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'"); ?> Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-537440 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 Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-537496 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? Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-537618 Share on other sites More sharing options...
cheechm Posted May 10, 2008 Author Share Posted May 10, 2008 Bumpy.... Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-537739 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'"); ?> Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-537757 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. Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-537858 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 Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-538188 Share on other sites More sharing options...
cheechm Posted May 11, 2008 Author Share Posted May 11, 2008 Bumpity. Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-538469 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'"); ?> ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-538474 Share on other sites More sharing options...
cheechm Posted May 13, 2008 Author Share Posted May 13, 2008 That doesn't work. Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-540161 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 Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-540207 Share on other sites More sharing options...
cheechm Posted May 13, 2008 Author Share Posted May 13, 2008 Neither does that unluckily. Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-540229 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! Link to comment https://forums.phpfreaks.com/topic/105000-solved-inserting-multiple-values-into-mysql/#findComment-540238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.