leslie.g Posted March 1, 2012 Share Posted March 1, 2012 Hi I currently have this form to update the names of each session in the database. However how do I go about updating more than one value. I also want to update the 'order' swell as the name so the order in which they're displayed is updated I want to have another text field next to it for the order which will just be a number but i can't figure out how to update both in the foreach() function <?php if($_POST['update_sessions']){ foreach($_POST as $sessionid => $sessionname){ mysql_query("UPDATE `sessions` SET `name`='".mysql_real_escape_string($sessionname)."' WHERE `id`='".mysql_real_escape_string($sessionid)."'"); } echo("Done!"); } ?> <form method="post"> <?php $getsessions = mysql_query("SELECT * FROM `sessions` ORDER BY `order`"); while($sessions = mysql_fetch_array($getsessions)){ echo("<input type='text' name='".$sessions['id']."' value='".$sessions['name']."'><br />\n"); } ?> <input type="submit" value="Update" name="update_sessions" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/258014-mysql-update-form-help/ Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 something like this mysql_query("UPDATE sessions SET name='".mysql_real_escape_string($sessionname)."', order='$order' WHERE id='".mysql_real_escape_string($sessionid)."'"); Quote Link to comment https://forums.phpfreaks.com/topic/258014-mysql-update-form-help/#findComment-1322680 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.