moran1409 Posted February 26, 2011 Share Posted February 26, 2011 hello all, i am trying to edit a mysql table from the browser using these codes: edit.php: include"db.inc.php";//database connection $order = "SELECT * FROM prices"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ echo ("<tr><td>$row[id_number]</td>"); echo ("<td>$row[product]</td>"); echo ("<td>$row[price]</td>"); echo ("<td><a href=\"edit_form.php?id=$row[id_number]\">Edit</a></td></tr>"); } edit_form.php <table> <? include "db.inc.php";//database connection $order = "SELECT * FROM prices where id_number='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> <form method="post" action="edit_data.php"> <input type="hidden" name="id" value="<? echo "$row[id_number]"?>"> <tr> <td>Product</td> <td> <input type="text" name="product" size="20" value="<? echo "$row[product]"?>"> </td> </tr> <tr> <td>Price</td> <td> <input type="text" name="price" size="40" value="<? echo "$row[price]"?>"> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </form> </table> edit_data.php include "db.inc.php"; $order = "UPDATE prices SET product='$_POST[product]', price='$_POST[price]' WHERE id_number='$id'"; mysql_query($order); header("location:edit.php"); the table: CREATE TABLE IF NOT EXISTS `prices` ( `id_number` int(3) NOT NULL, `product` varchar(30) DEFAULT NULL, `price` int(6) DEFAULT NULL, PRIMARY KEY (`id_number`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; the data is displayed correctly but i can't change the data... Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/ Share on other sites More sharing options...
moran1409 Posted February 27, 2011 Author Share Posted February 27, 2011 anyone??? Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180338 Share on other sites More sharing options...
ronnie3148 Posted February 27, 2011 Share Posted February 27, 2011 I haven't been in coding for awhile and I am just getting back in it, but try this at edit_data.php <?php include ("db.inc.php"); $product = $_POST["product"]; $price = $_POST["price"]; $order = "UPDATE prices SET product='$product', price='$price' WHERE id_number='$id'"; mysql_query($order); header("location:edit.php"); ?> edited this should work... Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180343 Share on other sites More sharing options...
moran1409 Posted February 27, 2011 Author Share Posted February 27, 2011 no that didn't work Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180419 Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2011 Share Posted February 27, 2011 In edit_data.php, where is your code that is setting $id from the form field so that the query would match a row in your table? Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180420 Share on other sites More sharing options...
moran1409 Posted February 27, 2011 Author Share Posted February 27, 2011 "In edit_data.php, where is your code that is setting $id from the form field so that the query would match a row in your table?" i don't understand... i posted the entire code there is nothing else... Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180509 Share on other sites More sharing options...
ronnie3148 Posted February 28, 2011 Share Posted February 28, 2011 He is saying maybe make a hidden field that has the id number in it, because maybe it is not finding $id... and is this session based? did you forget to start your session? Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180699 Share on other sites More sharing options...
moran1409 Posted February 28, 2011 Author Share Posted February 28, 2011 edit data (changed - but still not working...) include "db.inc.php"; $order = "UPDATE prices SET product='$product', price='$price' WHERE id_number='$id'"; mysql_query($order); echo $price; i don't fully understand you both, all i am trying to do is update a mysql table could you tell me which part of the code should i change and how will i do that? Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180827 Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 They are asking you where $id gets its value. if $id does not have a valid value your UPDATE will not work. Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180834 Share on other sites More sharing options...
moran1409 Posted February 28, 2011 Author Share Posted February 28, 2011 this is in edit.php echo ("<td><a href=\"edit_form.php?id=$row[id_number]\">Edit</a></td></tr>"); i added in edit_form: $id = $_GET['id']; somehow it gets lost in the way... i don't know what to do!!! Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1180938 Share on other sites More sharing options...
Muddy_Funster Posted March 1, 2011 Share Posted March 1, 2011 change this echo ("<td><a href=\"edit_form.php?id=$row[id_number]\">Edit</a></td></tr>"); to echo '<td><a href="edit_form.php?id='.$row['id_number'].'">Edit</a></td></tr>'; and see how you get on Quote Link to comment https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/#findComment-1181143 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.