Hi,
I'm trying to create a simple guestbook following a tutorial. I stucked at some point.
So this is where I am; i've created the form and some php code as well as the database table
<?php
require($_SERVER["DOCUMENT_ROOT"]."/guest/config/db_config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die ("error connection");
mysql_select_db($db_name, $connection);
$name = $_POST["txt_name"];
$len = strlen($name);
//Only write to database if there's a name
if ($len > 0)
{
$email = $_POST["txt_email"]; //see if there is an email element
$comment = $_POST["txt_comment"];
$date = time(); //returns the date in seconds
//Now, have to set up mysql query
$query = "INSERT INTO guestbook (ID, name, email, comment, date_auto) VALUES (NULL '$name', '$email', '$comment', '$date')";
//Now, we have to run the actual query
mysql_query($query, $connection) or die (mysql_error()); //save it to the database or send an error
}
?>
<html>
<head>
<title>Guestbook</title>
</head>
<body>
<center>
<form action="<?php echo $SERVER[PHP_SELF]; ?>" method="POST">
<font face="arial" size="1">
Name: <input type="text" name="txt_name">
Email: <input type="text" name="txt_email"><br /><br />
Comment: <br />
<textarea style="width: 75%" rows="10" name="txt_comment"></textarea>
<center><input type="submit" value="Submit"></center>
</font>
</form></center>
</body>
</html>
This is the table i1ve created:
CREATE TABLE IF NOT EXISTS `guestbook` (
`ID` int(10) unsigned NOT NULL auto_increment,
`name` varchar(64) default NULL,
`email` varchar(64) default NULL,
`comment` text,
`date_auto` int(10) unsigned default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The form appears in the browser but when I try to send a message i get this sql error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tom', 'dtommy79@yahoo.com', 'test message', '1219671750')' at line 1
I don't really know what it means
Any help is appreciated