Hi im trying to make something like guestbook but adding messages dont work. I cant add them to my table and read them. Can someone help me and correct my errors im am begginer in php . this are my errors :
Notice: Undefined variable: name in C:\xampp\htdocs\addguestbook.php on line 17
Notice: Undefined variable: email in C:\xampp\htdocs\addguestbook.php on line 17
Notice: Undefined variable: comment in C:\xampp\htdocs\addguestbook.php on line 17
Successful
<?php
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="bai2011_cba_pl"; // Database name
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page
}
else {
echo "ERROR";
}
mysql_close();
?>
this is my table :
guestbook
id
int(4) NOT NULL auto_increment,
name
varchar(65) NOT NULL default '',
email
varchar(65) NOT NULL default '',
comment
longtext NOT NULL,
datetime
varchar(65) NOT NULL default '',
PRIMARY KEY (id
)
)ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;