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

Simple Address Book

By Angela Bradley, About.com

3 of 6

Add A Contact

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

if ( $mode=="added")
{
mysql_query ("INSERT INTO address (name, phone, email) VALUES ('$name', '$phone', '$email')");
}

Next we give the users an opportunity to add data. Since we are using the same PHP page to do everything, we will make it so that different 'modes' show different options. We would place this code directly under that in our last step. This would create a form to add data, when in add mode. When submitted the form sets the script into added mode which actually writes the data to the database.

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. MySQL Address Book - Online Address Book - PHP Address Book

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

All rights reserved.