Creating the database for your PHP & MySQL login script |

PHP & MySQL Login Tutorial Series
Pt1: Introduction
Pt2: Setting up the database
Pt3: The front end and user validation
Pt4: The code to privatize a page
Pt5: Logout function and clearing the session ID
Part 2: Creating the MySQL database
Before we get to programming, let’s setup the databases. You will need to create two different tables—one for user accounts and the other for sessions. Setup the tables as follows:
Table name: user_accounts
Field 1: userid, int(10), primary key, auto_increment
Field 2: username, varchar(10)
Field 3: password, varchar(32)
Field 1 will store our user id number and will be a primary key for unique user identification. Field 2 is our username with a maximum of 10 characters. The number of characters can be set at whatever you’d like. Field 3 is our password field and, for this example, needs to be a minimum of 32 characters. You can use a larger size, however all passwords will be 32 characters in length.
Table name: user_sessions
Field 1: sessionid, varchar(32), primary key
Field 2: userid, int(10)
Field 3: timestamp, int(12)
Field 1 will store our temporary session id and must be 32 characters as well as a primary key. Field 2 is our user id and its size must be equal to the size you selected in the user_accounts table. Field 3 is our time field. There are several ways to store a time in a database, however we will be storing the Unix timestamp.

(+5 rating, 11 votes)







Leave a Reply