Displaying Users on a User Registration Website

 

Introduction.  Now we need to address issues of making things about registered users available to others.  You could choose to make this more secure or more open depending on the situation.  Since we will require more security when users want to modify or delete their information we will leave this situation more open.  In addition, we will not display all of the information that is available on each user.

Probably the messiest aspect of all of this is getting things to display in a table and coordinating the concomitant jumping between HTML and PHP.  We are also going to be needing to pull the information out of the database table.

The file should be called display_user_registration.php.

 

<?php

// assign the values for database access
$host = "localhost";
$user = "your_user_name";
$password = "your_password";
$db_name = "database_name";
$table_name = "user_registration";

// connecting to the database on battcave.com
$link = mysql_connect($host, $user, $password);
// constructing the query string
$query_string = "SELECT * FROM $table_name";
$result_set = mysql_db_query($db_name, $query_string, $link);

// display the result set in a table
// initializing the table and the column headers

print("<table border=2 width=900 align=center>");
print("<tr align=center valign=top>");
print("<td align=center valign=top><font size=4><b>User ID</b></font></td>");
print("<td align=center valign=top><font size=4><b>Name</b></font></td>");
print("<td align=center valign=top><font size=4><b>EMail Address</b></font></td>");
print("<td align=center valign=top><font size=4><b>Interests</b></font></td>");
print("<td align=center valign=top><font size=4><b>Credit Card</b></font></td>");
print("<td align=center valign=top><font size=4><b>Education</b></font></td>");
print("<td align=center valign=top><font size=4><b>Registration Date</b></font></td>");
print("</tr>");
// looping through the resultset appending a new row for each record
while ($row = mysql_fetch_array($result_set))
{

// initializing the interests display
$php_interest = "";
$jsp_interest = "";
$mysql_interest = "";
// developing a string to display the user interests
if ($row[php_interest] != "") $php_interest = "PHP<BR>";
if ($row[jsp_interest] != "") $jsp_interest = "JSP<BR>";
if ($row[mysql_interest] != "") $mysql_interest = "MySQL<BR>";
print("<tr align=center valign=top>");
print("<td align=center valign=top><font size=4> $row[user_id] </font></td>");
print("<td align=center valign=top><font size=4> $row[first_name] $row[last_name] </font></td>");
print("<td align=center valign=top><font size=4> $row[email] </font></td>");
print("<td align=center valign=top><font size=4> $php_interest $jsp_interest $mysql_interest</font></td>");
print("<td align=center valign=top><font size=4> $row[credit_card] </font></td>");
print("<td align=center valign=top><font size=4> $row[education] </font></td>");
print("<td align=center valign=top><font size=4> $row[registration_date] </font></td>");
print("</tr>");

}
mysql_close($link);
print("</table>");
print("<p align='center'><a href='user_registration_home.html'><font size = 4><b>User Home Page</b></font></a></p>")
?>
<html>
<head>
<title>Retrieving from a Table in MySQL and Displaying Using PHP</title>
</head>

<body bgcolor = "003344" text="cccccc" link="00aacc" vlink="007799">
</body>
</html>

 

The form should look like the following.

 

 

You should notice how we have displayed all of the characteristics of each user, for example we have omitted their password.

Notice how I have included a link back to the homepage.  Another, possibly more intelligent way to do this would be to put links to the four basic types of functionalities we want to provide

  • add a user
  • display users
  • delete a user
  • modify a user

on every page.