Editing a record.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jdleon
Forum Newbie
Posts: 4
Joined: Wed Nov 11, 2009 10:48 pm

Editing a record.

Post by jdleon »

I need to edit a record, and I have been reading and researching on the web and have found examples but they are too complicated. Especially since I am just learning to code in php. Is there a basic simple code to start out with? So, far I have a user list showing first name, last name, username and password. At the end I have an "Edit" link, which will go to my edit.php file, and I can edit any of the user's information. The variables do get pass to the page with no problems, I'm just have a hard time getting started with the editing part.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Editing a record.

Post by Christopher »

There are several ways to do this. Here is some basic logic:

HTML:

Code: Select all

<form action="toself.php" method="post">
<input type="hidden" name="submit" value="yes"/>
<input type="text" name="name" value="<?php echo $values['name']; ?>"/>
<input type="submit" name="save" value="save"/>
</form>
PHP:

Code: Select all

// initialization
 
if (/* the for has been submitted */) {        // some check like isset($_POST['submit'])
 
     // check all fields that have some rule associated with them
 
     if (! $errors) {
 
          // do something with the data, like save it to a database
 
          // redirect to successful submission page
          return;
 
     } else {
 
          // get error messages
 
     }
 
} else {     // not submitted, so first time
 
     // initialize all form fields to default values
 
}
 
// display the HTML form
(#10850)
Post Reply