I am creating a RSVP management system for a site. I have already created a page that displays all the results of people who have already registered. I want to be able to create a link on each row that allows the information to be brought up in another page and allows me to edit or delete the information. My thought is that I could but all the information in corresponding text boxes and make the values the original information. I could then change the values and use a update php script.
Could really use some help on this, as I am still a beginner at PHP and MYSQL. Will post code if it will make i easier, but really looking for the code that I would add in the loop on the display page and then the code for an edit.php page that will get the information from only the row selected.
Now in your edit.php, you will need to do something similar
PHP Code:
$member_id = $_GET['id'];
$results = mysql_query("select * from member where id = $member_id");
$row = mysql_fetch_assoc($results);
Now all your information is in the $row variable. You may get eg) $row['name'] etc. Place the information in a form and submit to something similar to your register page.
In delete.php you could do this.
PHP Code:
header("Location: index.php"); // bring back to original page
$member_id = $_GET['id'];
mysql_query("delete from member where id = $member_id limit 1");
I hope this helps. I haven't tested the code but you're going to be doing something similar for edit and delete.
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
header("Location: rsvp_view.php"); // bring back to original page
$member_id = $_GET['id'];
mysql_query("delete from member where id = $member_id limit 1");
?>
When I click edit, I don't get anything in the guest 1 text box, and I get this error "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/m/a/r/markandmichell/html/manager/edit.php on line 22
"
When I click delete, the browser processing, but nothing is deleted on the screen. Not sure what I am doing wrong, but some help would be much appreciated.
Thanks for looking at the code, even though you are at work. I changed the link to incorporate the your changes. I still for some reason though get a url without a row identification (edit.php?=). So still not sure what isn't working. I am hoping that you will have some time after work to go through it all. Let me know if you want me to post anymore of the code.
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
header("Location: rsvp_view.php"); // bring back to original page
$member_id = $_GET['id'];
mysql_query("delete from member where id = $member_id limit 1");
?>
So here is all the code. Again, I want to be able to open a specific row in the edit page and makes changes and then execute an update script. I also want to be able to just delete an entire row all together as well. Any advice would be a great help.
I have an id as increment, but I still have a problem. I was able to delete when click on the delete link, but when I click on the update, I've got the error. here's my code:
$conn = mysql_connect($hostname, $username, $password) or die ("mysql error");
$selected = mysql_select_db("first_test",$conn) or die ("database error");
// delete record
$delete_record = $_GET['delete'];
if (isset($_GET['delete']))
{
mysql_query("delete from people where id = '$delete_record'");
echo $delete_record . ' was deleted!<p>';
}
// display result
$result = mysql_query("select * from people order by id");
echo "<table border = '1' align='center' width='70%'>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Delete Record</th>
<th>Update Record</th>
</tr>";
Bookmarks