qq_tracker_code_advanced_default

Easy PHP Guestbook Part 2 – The Database

0


In this part of the tutorial I will cover briefly how to setup a new database and create the php file that will have the database connection strings.

First things first, create a new database and name it guestbook, assign a new user to this database name the new user guestbook, assign a password for this user 12345 will work for now.

Creating databases and assigning users will not be covered in this tutorial, this should be covered in a help file provided by your hosting company.

Once your database has been created and a user has been added you will need to setup the tables that will store each guestbook entry.

For starters lets create a table and call it guestbookentries

You will need 5 columns in this table:

  1. guestbookentryid – Set this column as the primary key and set it to auto increment, the type will be BIGINT
  2. name – The type will be TEXT
  3. date – The type will be DATETIME
  4. website – The type will be TEXT
  5. entry – The type will be TEXT

I suggest using phpmyadmin to setup this table in the database, if you don’t feel up to creating this table you can download this file guestbookentries.sql

You can import that file using phpmyadmin and it will create the table for you.

Once the table has been created you need to create a new file and name it sqlcon.php and place the following code into this file.

<?php

$dbusername=”guestbook”;
$dbpassword=”12345″;
$database=”your_database_name”;

//This line of code connects to the mysql server
mysql_connect(localhost,$dbusername,$dbpassword,true);

//This line of code selects the correct database
@mysql_select_db($database) or die (“Unable to select database”);

?>

Upload this file to a new folder on your server, create a folder called guestbook on your servers root and upload the sqlcon.php file to there.

You can point your browser to this file http://yourservername.com/guestbook/sqlcon.php

If the page comes up blank then everything is working as it should, if it comes up with an error then you’ve made a mistake somewhere. I’d be happy to help troubleshoot any problems you are having up to this point.

This concludes Part 2 of the tutorial

Similar Posts:

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Be Sociable, Share!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!