roldahayes Posted July 11, 2008 Share Posted July 11, 2008 I have a page where a user can type a famous quote into a form and then select which page it appears on. The quote is then displayed on the relivant page. My question is, how would i create a form to let them edit the quotes stored in the database? Go easy on me, quite new to this! <?php @$pfw_ip= $_SERVER['REMOTE_ADDR']; @$pageid = addslashes($_POST['pageid']); @$quote = addslashes($_POST['quote']); @$author = addslashes($_POST['author']); // Validation if (strlen($pageid) == 0 ) { header("Location: error.html"); exit; } if (strlen($quote) == 0 ) { header("Location: error.html"); exit; } //saving record to MySQL database @$pfw_strQuery = "INSERT INTO `quotes`(`pageid`,`quote`,`author`)VALUES (\"$pageid\",\"$quote\",\"$author\")" ; @$pfw_host = "*******"; @$pfw_user = "*******"; @$pfw_pw = "********"; @$pfw_db = "******"; $pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw); if (!$pfw_link) { die('Could not connect: ' . mysql_error()); } $pfw_db_selected = mysql_select_db($pfw_db, $pfw_link); if (!$pfw_db_selected) { die ('Can not use $pfw_db : ' . mysql_error()); } //insert new record $pfw_result = mysql_query($pfw_strQuery); if (!$pfw_result) { die('Invalid query: ' . mysql_error()); } mysql_close($pfw_link); header("Location: ok.html"); ?> Link to comment https://forums.phpfreaks.com/topic/114345-updating-records/ Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 SELECT the quote then just run an UPDATE query on it based on the ID of it. Link to comment https://forums.phpfreaks.com/topic/114345-updating-records/#findComment-588078 Share on other sites More sharing options...
roldahayes Posted July 12, 2008 Author Share Posted July 12, 2008 So how would I make that into a form? I was trying with this.... but getting nowhere! <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table> <tr> <td align="center">EDIT DATA</td> </tr> <tr> <td> <table border="1"> <? include"db.inc.php";//database connection $order = "SELECT * FROM quotes"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ echo ("<tr><td>$row[pageid]</td>"); echo ("<td>$row[quote]</td>"); echo ("<td>$row[author]</td>"); echo ("<td><a href=\"edit_form.php?id=$row[quote]\">Edit</a></td></tr>"); } ?> </table> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/114345-updating-records/#findComment-588328 Share on other sites More sharing options...
JasonLewis Posted July 12, 2008 Share Posted July 12, 2008 Okay, try replacing the PHP in that page with this: [code=php:0] <?php include("db.inc.php");//database connection $order = "SELECT * FROM quotes"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ echo ("<tr><td>$row['pageid']</td>"); echo ("<td>$row['quote']</td>"); echo ("<td>$row['author']</td>"); echo ("<td><a href=\"edit_form.php?id=$row['QUOTE_ID_FIELD']\">Edit</a></td></tr>"); } ?> Then in edit_form.php, you would grab the ID from the Query String ($id = $_GET['id']), then you would run a query to grab the data for that quote. Then with the data, populate a textarea with the quote and have a submit button to edit. Then on the processing just UPDATE the quote that has the same ID with the new data. Link to comment https://forums.phpfreaks.com/topic/114345-updating-records/#findComment-588330 Share on other sites More sharing options...
roldahayes Posted July 12, 2008 Author Share Posted July 12, 2008 That just returns a blank page??? Link to comment https://forums.phpfreaks.com/topic/114345-updating-records/#findComment-588331 Share on other sites More sharing options...
JasonLewis Posted July 12, 2008 Share Posted July 12, 2008 Well do you have any quotes? I'm assuming so. Check if you're query is returning anything my counting the rows. Do some debugging. Check the page source to see if it's writing it out properly. I wouldn't recommend copying and pasting code all the time as well. It can become messy. Just look at what I've done, then change yours. Link to comment https://forums.phpfreaks.com/topic/114345-updating-records/#findComment-588333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.