Adding information to the database
<?php
//enter your host details in here
$hostname = "localhost";
//enter your username in here
$username = "myusername";
//enter your password in here
$password = "mypassword";
//this is the database name
$database = "guestbook";
//make a connection with our info
$connection = mysql_connect($hostname , $username , $password)
or die("cannot make connection");
//connect to our database with our connection
$db = mysql_selectdb($database , $connection)
or die("cannot find database");
//insert values of the form into the guestbook table
$sql_query = "INSERT into guestbook VALUES ('','$name','$comments','$email')";
//store the result of the query in result in $result variable
$result = mysql_query($sql_query);
//display a message
echo "Thanks for submitting to our guestbook";
?>
back to building a guestbook