当我通过 php 表单提交留言簿详细信息时,它以“成功”结尾,但是当我查看 MySQL 数据库时,它只是创建了新条目,但除了自动 ID 和日期之外,没有任何详细信息。
这是表格:guestbook.php
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td><input name="name" type="text" id="name" size="40" /></td>
<td><input name="email" type="text" id="email" size="40" /></td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset"
name="Submit2" value="Reset" /></td>
这是脚本:addguestbook.php
$host="address"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="guestdb"; // 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>";
// link to view guestbook page
echo "<a href='viewguestbook.php'>View guestbook</a>";}
else {
echo "ERROR";}
mysql_close();