1. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    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!!
  2. #2
  3. No Profile Picture
    rod k
    Devshed Newbie (0 - 499 posts)
    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.



Similar Threads

  1. Problem Updating a MySql record with PHP
    By Lewis Matthews in forum PHP Development
    Replies: 6
    Last Post: September 26th, 2003, 06:57 PM
  2. Why Use ASP When There is PHP?
    By nintendong in forum ASP Programming
    Replies: 4
    Last Post: March 29th, 2003, 02:45 AM
  3. PHP and MySQL book
    By taalebi in forum PHP Development
    Replies: 4
    Last Post: November 15th, 2001, 10:47 AM
  4. PHP and MySQL on Apache Liux/Win 98
    By vu3prx in forum Apache Development
    Replies: 2
    Last Post: October 31st, 2001, 10:59 AM
  5. MySQL PHP problem
    By The Pie Man in forum PHP Development
    Replies: 6
    Last Post: April 24th, 2001, 06:17 PM

IMN logo majestic logo threadwatch logo seochat tools logo