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

Simple Address Book

By Angela Bradley, About.com

6 of 6

The Address Book

$data = mysql_query("SELECT * FROM address ORDER BY name ASC")
or die(mysql_error());
Print "<h2>Address Book</h2><p>";
Print "<table border cellpadding=3>";
Print "<tr><th width=100>Name</th><th width=100>Phone</th><th width=200>Email</th><th width=100 colspan=2>Admin</th></tr>"; Print "<td colspan=5 align=right><a href=" .$_SERVER[’PHP_SELF’]. "?mode=add>Add Contact</a></td>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr><td>".$info['name'] . "</td> ";
Print "<td>".$info['phone'] . "</td> ";
Print "<td> <a href=mailto:".$info['email'] . ">" .$info['email'] . "</a></td>";
Print "<td><a href=" .$_SERVER[’PHP_SELF’]. "?id=" . $info['id'] ."&name=" . $info['name'] . "&phone=" . $info['phone'] ."&email=" . $info['email'] . "&mode=edit&gt;Edit</a></td>"; Print "<td><a href=" .$_SERVER[’PHP_SELF’]. "?id=" . $info['id'] ."&mode=remove&gt;Remove</a></td></tr>";
}
Print "</table>";
?>
</body>
</html>
The bottom part of our script actually pulls the data from our database, puts it into an array, and prints it out. Using the PHP_SELF function with actual database data, we are able to link to add mode, edit mode, and remove mode. We pass the appropriate variables within each link, to let the script know which mode is needed.

From here you can make aesthetic changes to this script, or try adding more fields.

See Full Script Code

6 of 6

Explore PHP / MySQL

More from About.com

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

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

All rights reserved.