7. Signup Page - The Database
First things first! We need a storage area for our information. A database! I highly recommend using an admin system like phpMyAdmin, which should come with your webhosting package. There are dozens of other good ones out there. Feel free to suggest a few simple ones if you use a different admin system!!
I recommend this, because it's a lot easier than having to write out every command then execute it on your server - it does that for you! To make things simple, I'm going to use phpMyAdmin for here on out.
Go to your cPanel - and find your area for "MySQL Databases".
Create a new user with a password - mine is "FBAdm1n" with the password being "YourDBPassword".
Create a new Database - mine is "facebook".
Add the "FBAdm1n" user to "facebook" with ALL privileges.
(You should use your own User name and a different Database name)
To connect to our DB, open inc/load.inc.php and add
define("DB_SERVER", "localhost");
define("DB_USER", "FBAdm1n");
define("DB_PASS", "YourDBPassword");
define("DB_NAME", "Facebook");
$con = @mysql_connect(DB_SERVER, DB_USER, DB_PASS);
@mysql_select_db(DB_NAME, $con);
if(!$con)
{
die('Could not connect to the Database');
}
below the session_start() line. Save it, upload it, and reload index.php. If your page says "Could not connect to the Database" then some of your information was incorrect. Check the spelling, names, and make sure each Contstant has the right information in the right area.
If your page loads normally, you know it's connected to the DB.
Once you've connected to your DB, we need to make a few tables. We could do it using code, but I find the phpMyAdmin system is quicker/easier.
Open up phpMyAdmin and create a new table called "users" with 3 columns.
First column:
Name: UID
Type: INT
Length: 9
Default: NONE
Collation: (blank)
Attributes: (blank)
Null: Unchecked
Index: INDEX
AUTO_INCREMENT: Checked! (Very important)
Comments: (blank)
Second column:
Name: Email
Type: Varchar
Length: 50
Default: NONE
Collation: (blank)
Attributes: (blank)
Null: Unchecked
Index: UNIQUE (No duplicate emails are allowed)
AUTO_INCREMENT: Unchecked
Comments: (blank)
Third column:
Name: Pass
Type: Varchar
Length: 40
Default: NONE
Collation: (blank)
Attributes: (blank)
Null: Unchecked
Index: INDEX
AUTO_INCREMENT: Unchecked
Comments: (blank)
Storage Engine:
MyISAM (should be default)
Click Create/Save! Now we have a table for users to their login information.
Next, create another new table called "profiles" with 5 columns. (We will be adding more in the future).
Names: UID, Firstname, Lastname, Sex, Birthday
Types: INT, Varchar, Varchar, Tinytext, Varchar
Length: 9, 40, 50, 1, 11
Null: Uncheck them all!
Index: Unqiue, index, index, none, index (We index Birthday because of the birthday we'll make)
We should have 2 tables in our Database, "users" and "profiles".
Next we'll make the sign up form validate our input and if everything is validated good it will create a new user.
You can also download the .sql file, and import it through phpMyAdmin into your "facebook" database.