Page 1 of 1
Editing a record.
Posted: Thu Feb 11, 2010 4:08 pm
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.
Re: Editing a record.
Posted: Thu Feb 11, 2010 4:53 pm
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