Jump to content

MySQL Update Form help


leslie.g

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/258014-mysql-update-form-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.