Database-Driven User Authentication

Ever have something that you wanted to put on the internet for only a group of
people to see? Well then this script is for you. All you need is; PHP, and MySQL.
Create a MySQL database to store the usernames and passwords.

Now that you have a table named auth_users, you can now create an interface to add First names, Last Names, usernames, and passwords.

1) Type the following HTML:

2) Begin your form

3)Create an input field for the user’s first name with a text label:

4) Create an input field for the user’s last name with a text label.

5) Create an input field for the username with a text label.

6) Create an input field for the username with a text label.

7) Add a Submit button

8) Close your form and add some more HTML so that the document is valid:

9) Save the file as show_adduser.html
Create the back-end script
1) Start the php block
<?
2) Check that the values were acctually entered for all four fields. If they
weren’t, direct the user back to the form and exit the script.

3) Create a variable to hold the name of the database on which the table resides:

4) Create a variable to hold the name of the table you’re populating with this
script:

5) Create a variable to hold the reult of the mysql_connect() function. Include
the @ to suppress warnings, as well as the die() function to cause the script
to end and a message to display if the connection fails:

6) Create a variable to hold the reult of the mysql_select_db() function. Include
the @ to suppress warnings, as well as the die() function to cause the script
to end and a message to display if the selection of the database fails:

7) Create the SQL statement. The first parenthetical statement gives the names
of the fields to populate(in order), and the second parenthetical statement
sends the actual strings:

8) Create a variable to hold the result of the mysql_query() function. Include
the @ to suppress warnings as well as the die() function to cause the script
to end and a message to desplay if the query fails:

9) Close your PHP block:
?>
10) Add this HTML:

11) Add a link back to the original form:

12) Add some more HTML so that the document is valid:

13) Save the file with the name adduser.php.
That’s it upload and try it out.