Tables for the User Registration Website

 

Background.  In order to develop the database you are likeliest to need to connect to a pre-existing database you have on your website and create a table.  If you don't have a pre-existing database that has been developed by your hosting source you will first need to do that.

But on Battcave.com you have a MySQL database with the same name as the name of your web.  Since my web is called desaighuweb, that is the name of my database.  Given this you will need to create a user_registration table within this database. 

In order to make certain we work with all of the different form controls, and not much more, I have somewhat artificially influenced the structure of the table.  In addition, MySQL has a fairly strange feature for dealing with true/false or yes/no data.  When referencing a table in MySQL, the only things that will evaluate to false are 0 and blank "" or ''.  This requires a bit of finagling in the PHP to handle this.

The following is the PHP code to do this on Battcave.com.  It's not likely to be very different on your site.  You should call this file create_user_registration_table.php.

 

<html>
<head>
<title>Creating a Table in MySQL Using PHP</title>
</head>

<body>
<?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 = "CREATE TABLE $table_name
(user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(30) NOT NULL,
email VARCHAR(50),
password VARCHAR(16) NOT NULL,
php_interest ENUM('1',''),
jsp_interest ENUM('1',''),
mysql_interest ENUM('1',''),
credit_card VARCHAR(12),
education VARCHAR(10),
registration_date DATETIME NOT NULL)";

if (mysql_db_query($db_name, $query_string, $link))
{

print ("The query was successfully created<BR>");

}
else
{

print ("The query could not be created<BR>");

}

mysql_close($link);
?>
</body>
</html>

 

The formatting on the table create string should help you to see the fields.  The following table summarizes these and gives a brief description.

 

Control Type Name Corresponding Field Description
    user_id Auto incrementing integer which will be the primary key.
text box txt_first_name first_name Control and field corresponding to the first name of the user.  This will make use of a variable length character field.
text box txt_last_name last_name Control and field corresponding to the last name of the user.  This will make use of a variable length character field.
text box txt_email email Control and field corresponding to the email address of the user.  This will make use of a variable length character field.
password text box txt_password password Control and field corresponding to the email address of the user.  This will make use of a variable length character field.
checkbox chk_php php_interest The user will check this checkbox if they profess an interest in PHP.  This is characterized by an ENUM type which can be either a 1 or a blank ''.
checkbox chk_jsp jsp_interest The user will check this checkbox if they profess an interest in JSP.  This is characterized by an ENUM type which can be either a 1 or a blank ''.
checkbox chk_mysql mysql_interest The user will check this checkbox if they profess an interest in MySQL.  This is characterized by an ENUM type which can be either a 1 or a blank ''.
select/option sel_credit_card credit_card The user will select which of the credit cards they will use. The options are
  • Discover
  • MasterCard
  • Visa

This is characterized by a variable length character which will store which type of credit card they've selected.

radio button rb_education education The user will check one of the radio buttons to represent their level of education. The radio buttons are
  • NoCollege
  • College
  • Masters
  • PhD

This is characterized by a variable length character which will store which type of credit card they've selected.

 

    registration_date This will be placed in a DATETIME field automatically by the code so the user will not enter it or be able to access it.

 

The code is configured to tell you whether the CREATE was successful. 
  • Notice how the $link is constructed
    • $link = mysql_connect($host, $user, $password);
    • based on
      • $host = "localhost";
      • $user = "your_user_name";
      • $password = "your_password";
  • Notice how we first develop the $query_string
  • Notice how the query is actually executed with
    • mysql_db_query($db_name, $query_string, $link)
    • based on
      • $db_name = "database_name";
      • the $query_string
      • the $link developed earlier

You might be able to verify the existence of this table and its structure on your web host.