Creating a Connect.inc.php Page

Creating a connect.inc.php is a little trick I learned from a developer I used to work with. The idea is that you store important information here that you would have on every page, by putting it in a seperate connect page you allow yourself to avoid the hastle of re-writing this information with every new page you create. This is what the connect.inc.php page looks like.

<?php
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
session_start();
?>
Alright. So let’s take a look at this line by line and analyze it. Don't forget to write this out in your own connect.inc.php file because we'll be needing this in part 2.
mysql_connect("localhost", "name", "pass") or die(mysql_error());

Alright so this first line is making a call to our server, in this case localhost (in most instances this will stay the same). Name and Pass correspond to your username and password with your mysql database. You would have defined these when you set up your database.

mysql_select_db("test") or die(mysql_error());

 This selects our database. This isn’t necessarlily mandatory, but is good for when you’re starting out, your site should only be using one database. This is means that when you make an sql call you’re doing it to test. Test is the name of your database. You can change this to what ever.

session_start();
This is starting our sessions. Sessions are used to store important information on your site. This allows us to keep track of a username, passwords and other important information.

Back | Forward