1. Home
  2. Computing & Technology
  3. PHP / MySQL

Simple Address Book

By Angela Bradley, About.com

4 of 6

Updating Data

if ( $mode=="edit")
{
Print '<h2>Edit Contact</h2>
<p>
<form action=';
echo $PHP_SELF;
Print '
method=post>
<table>
<tr><td>Name:</td><td><input type="text" value="';
Print $name;
print '" name="name" /></td></tr>
<tr><td>Phone:</td><td><input type="text" value="';
Print $phone;
print '" name="phone" /></td></tr>
<tr><td>Email:</td><td><input type="text" value="';
Print $email;
print '" name="email" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" /></td></tr>
<input type=hidden name=mode value=edited>
<input type=hidden name=id value=';
Print $id;
print '>
</table>
</form> <p>';
}

if ( $mode=="edited")
{
mysql_query ("UPDATE address SET name = '$name', phone = '$phone', email = '$email' WHERE id = $id");
Print "Data Updated!<p>";
}
The edit mode is similar to our add mode except it pre-populates the fields with the data we are updating. The main difference is that it passes the data to the edited mode, which instead of writing new data overwrites old data using the WHERE clause to make sure it only overwrites for the appropriate ID.
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Online Address Book - PHP Address Book - Address Book Tutorial

©2009 About.com, a part of The New York Times Company.

All rights reserved.