Search the Community
Showing results for tags 'mysql mass update form'.
-
Hey people, I am faced with a problem that I need guidance with in order to solve. I have a catering website that is connected to a mysql database that has a back end to do changes to the menu. I have created an update page that originally updated the price but I was asked for it to update all the fields with any changes being made on the page, sounds simple right? Only problem is, is that the data that is being displayed is pulled from the database and displayed as values in input boxes so that the user can make changes. Each input box has a nameid which is a unique number that is pulled from the database that is stored in a field for each entry. I want it so that the user can change any input box data and click on the one button and it update the records to each correct field based on their own unique id. Here is the code for the front end <form action="chstarterprice.php" method="post"> <br><br> <?php include("connection.php"); $result= mysql_query("SELECT title, subtext, nameid, category, price FROM starters"); while($row = mysql_fetch_array($result)) { $nameid = $row['nameid']; $title = $row['title']; $subtext = $row['subtext']; $category = $row['category']; $price = $row['price']; echo"<table>"; echo"<tr>"; echo"<td width=\"70px\">"; echo"<p class=\"form2\">"; echo "<b>Title</b>"; echo"</td>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo "<b>Subtext</b>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo "<b>Category</b>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo "<b>Price</b>"; echo"</td>"; echo"</tr>"; echo"<tr>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$title\">"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$subtext\">"; echo"</td>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$category\">"; echo"</td>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$price\">"; echo"</td>"; echo"</tr>"; echo"<tr>"; echo"</tr>"; echo"</table>"; } mysql_close($con); ?> <br> <input name="Submit" type="submit" value="Change" /></p> </form> Here is the backend script that processes the form data <? ob_start(); ?> <?php include("connection.php"); $nameid = $_POST['nameid']; $query = "update starters set title, subtext, nameid, category, price = ('$_POST[nameid]') where 'starters'.'nameid' = '$nameid' or die(mysql_error)"; if(mysql_query($query)){ header("location:change-prices.php");} else{ header("location:change-prices.php");} ?> <? ob_flush(); ?> If you guys can point me in the right direction with the code to make this work I would be greatly appreciated, I am really sure that it has something to do with the backend script as opposed to the front end. Please get back to me, thanks guys. Mitch