• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

Getting to know phpMyAdmin with MySQL building a address Book.

November 19, 2012 by Rick Hernandez Leave a Comment

Testing out my development environment with XAMPP, I created a HolaMundo.php file to try out my new MySQL database and some echo commands from PHP it seemed simple enough although the dollar signs are a little awkward to type. The file starts with a stage that just tells the HTML document that I will be using PHP programming language this can be inserted into any part of the HTML document. Next, I use mysql_connect this just passes my credentials to the database which is at localhost and username root with no password. after that, i have to call the Addressbook database somehow so I use mysql_select_db and that gets the database. Lastly, I create a variable to store the database in result this could have been called anything and store the query from colleague table. after this its just standard XHTML markup to prepare the document for the new data coming in. Next, I create a while loop while ($row = mysql_fetch_array($result)) results get passed into the while loop and iterates through to display id firstName lastName telephone email and favorite color and this is done with a simple echo command. and the last parts closes the current connection and cleans up memory.

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("addressBook");

$result = mysql_query("SELECT * FROM colleague");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3c.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
<html xmins="http://www.w3.org/1999/xhtml">

<head>
<title>Address Book</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>
<h1> Address Book</h1>
<table border="1" cellpadding="2" cellspacing="3"
summary="Table holds colleague contact information">

<tr>e
<th>ID:</th>
<th>First Name:</th>
<th>Last Name:</th>
<th>Phone Number:</th>
<th>Email Address:</th>
<th>Favorite Color:</th>
</tr>

<?php

// loop threw all the table rows in database
while ($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstName'] . "</td>";
echo "<td>" . $row['lastName']  . "</td>";
echo "<td>" . $row['telephone'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['favoriteColor'] . "</td>";
echo "</tr>";

} // end of the while loop

//free memory an close database connection
mysql_free_result($result);
mysql_close();

?>

</table>
</body>
</html>
Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: MySQL, PHP

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in