November 8th, 1999, 10:32 PM
Any ideas on how I would allow a user to edit their record in a MySQL database through a PHP script. I want to allow a user to be able to edit/update registration information they have entered previously.
Alternatively, how 'bout a method for pre-filling out a form with data from a MySQL database, allowing the user to edit as necessary, and when submitted posting that record to the database with a new date/time.
Any help appreciated!!
November 9th, 1999, 07:11 AM
This is a very simple procedure.
You just have to read the relevent record from the table and use the fields as value in the HTML <input> tags.
To keep this short, I'm assuming you've connected to the db and that $name contains the users name:
$result=mysql_query("select name,address,city,zip,phone from info where name='$name'");
<form action="changeinfo.php3" method=post>
<input type=hidden name="oldname" value="<? print $data[name] ?>">
NAME:<input type=text name="name" value="<? print $data[name] ?>">
Address:<input type=text name="address" value="<? print $data[address] ?>">
// you get the idea
then in changeinfo.php3 (assuming you've checked the validity of the entries) you can use this query:
"replace into info values ('$name','$address','$city','$zip','$phone') where name='$oldname')"
Using the $oldname allows the user to modify the name and still update the old record. However, using a unique index for this would be better.