Easy PHP Guestbook Part 4 – Submitting to the Database


In Part 4 of the Easy PHP Guestbook tutorial we will cover creating the inserting data into the database that was filled out in the user submission form.

Open the guestbookform.php file from part 3 and put the following code in it at the very top of the file:

     $name = $_POST["guestbookname"];
     $date = time();
     $website = $_POST["guestbookwebsite"];
     $entry = $_POST["guestbookentry"];
     mysql_query(“insert into guestbookentries (name,date,website,entry) values (‘$name’,’$date’,’$website’,’$entry’)”);
echo “Your entry has been submitted”;

This part of the script does 3 things, it checks to see if the submit button has been pressed, if it has then it assigns the values from the submission form to variables, and then takes those variables and inserts them into the database. Finally it will output a message stating that the entry has been successfully entered into the database.

This concludes Part 4 of the tutorial, in Part 5 we will cover how to display the entries that are in the database. Part 5 will also be the last part of the tutorial at which point I will make a more advanced guestbook script along with an admin section to manage entries and will sell it on this site for $5.00

Similar Posts:

VN:F [1.9.22_1171]
Rating: 7.7/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
Easy PHP Guestbook Part 4 – Submitting to the Database, 7.7 out of 10 based on 3 ratings
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!