seriousdamage Posted December 25, 2007 Share Posted December 25, 2007 Hi, I have just begun to create my first database, after I query the DB, the records are shown in a table, I would like to have for every record returned a possibility to be able to modify it by using a form and then resubmit into the database the changed record. below is the search script I use, could anyone help me with this? <?php $where = @$_POST['name'] ; $trimmed = trim($where); //trim whitespace from the stored variable // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($where)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } $link = mysql_connect('localhost', 'Username', 'password') or die(mysql_error()); mysql_select_db("contacts"); $where = mysql_real_escape_string ($_POST['name']); $query = 'SELECT * FROM contacts WHERE name=\''.$where.'\''; $sql = mysql_query($query); while ($row = mysql_fetch_object($sql)) { //print your data as you like echo "<table border=1><tr><td>$row->name</td><td><a href=delete.php?del=$row->name>Delete</a></td><td><a href=modify.php?mod=$row->name>Modify</a></td></tr></table>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83135-how-to-modify-a-record/ Share on other sites More sharing options...
drummer101 Posted December 25, 2007 Share Posted December 25, 2007 $sql = mysql_query("UPDATE _____ SET ....."); Quote Link to comment https://forums.phpfreaks.com/topic/83135-how-to-modify-a-record/#findComment-422919 Share on other sites More sharing options...
revraz Posted December 25, 2007 Share Posted December 25, 2007 Is your goal to search on an exact entry or part of it? For example, your code will only find "joe" if "joe" exists. If "joseph" exists, your code won't find it. So you may want to either broaden your search by using LIKE along with % or provide a list of all entries and then click on one to edit. Quote Link to comment https://forums.phpfreaks.com/topic/83135-how-to-modify-a-record/#findComment-422948 Share on other sites More sharing options...
seriousdamage Posted December 26, 2007 Author Share Posted December 26, 2007 Thanks revraz, that is a good tip which I need to use. But the part I can't make work is : when the query returns the records, are returned in a simple html table, I am trying to then select one of the records and output it in a form so that I can change it and after that I can update it by re-submitting to form. How can I output a record in a form after is in an html table? Quote Link to comment https://forums.phpfreaks.com/topic/83135-how-to-modify-a-record/#findComment-423394 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 When you display the table, you create a URL to the Record ID of that record. So when you click on it, you can use GET to edit that particular record. Quote Link to comment https://forums.phpfreaks.com/topic/83135-how-to-modify-a-record/#findComment-423427 Share on other sites More sharing options...
interpim Posted December 26, 2007 Share Posted December 26, 2007 in your table add another field for a link like Revraz has mentioned... write it with the id# as the link. such as echo "<a href='editpage.php?id=$id'>EDIT THIS RECORD</a>"; // $id will be your variable assigned the sql unique id your table gives it. on your editpage.php just have a form for the fields you want to edit, then use the submit script to update the database for that ID# Quote Link to comment https://forums.phpfreaks.com/topic/83135-how-to-modify-a-record/#findComment-423599 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.