Now that we have our MySQL table set up, we need to create a file called
stats.php. In this file we will have all of our code.
The first segment in ths code will be to connect to the MySQL table.
CODE
<php
//---------------------
// Define Some Connection Info
//---------------------
$host = 'hostname';
$username = 'username';
$password = 'password';
$db_name = 'database_name';
$tbl_name = 'stats'; // table name (should be correct unless changed in the mysql query)
This code defines some variables for us, so conecting to the database is easier, instead of typing all of this information in. It is pretty self explanatory.
This next chunk of code actually connects to the Database (It will be explained below)
CODE
//---------------------
// Connect To the Database
//---------------------
$sql_connect = mysql_connect("$host", "$username", "$password") or die("MySQL Connection Failed: " . mysql_error());;
$db_connect = mysql_select_db("$db_name")or die("Could not select DB: " . mysql_error());;
mysql_connect connects to our MySQL database using the variables we defined above. If it fails in connecting it will print the mysql error.
mysql_select_db selects the db which we will be storing our information in. Once again, if it fails, it will print the mysql error.
Now we can go on to the actual code of our script.