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
- Easy PHP Guestbook Part 5 – Retrieving from the Database
- Easy PHP Guestbook Part 3 – The Form
- Easy PHP Guestbook Part 2 – The Database
- PHP Basics : Variables
- Easy PHP Guestbook Part 1 – Does my server meet the minimum requirements ?