I’m trying to do a php/mysql guestbook. Very simple and strait forward. But it will only work once, then breaks. I don’t know if it’s the code or the way I have the table in mysql set up. here’s the code.
[php]
Guestbook Comments | ||
First Name | : | |
Last Name | : | |
: | ||
Comment | : | |
[php]
Guestbook <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name// Connect to server and select database.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);
// Get values from form
$name=$_POST[‘name’];
$lastname=$_POST[‘lastname’];
$email=$_POST[‘email’];
$comment=$_POST[‘comment’];
// Insert data into mysql
$sql=“INSERT INTO guestbook(name, lastname, email, comment)VALUES(’$name’, ‘$lastname’, ‘$email’, ‘$comment’)”;
$result=mysql_query($sql);
// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;
echo “Back to main page”;
}
else {
echo “ERROR”;
}
// close connection
mysql_close();
?>
[/php]It seems to write things one time. then I try it a second time and it stops working. I delete the table and start over and it’s good again. This came from a tutorial, but I did do some revisions.