创建评论框;文本正文不会被转发


creating comment box; text body does not get forwarded

我正试图在网站上创建一个评论区。我用来尝试这一点的页面只是在必要的时候。我的问题是评论体没有被转发到我设置的表中。不过,日期会被发送并存储。我已经在下面发布了代码。我已经看了这个代码一段时间了,开始感到沮丧。研究没有得到任何答案。我将把这件事交给你们,作为我的最后手段。感谢您的帮助或指导。

前端代码:

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr>
    <td><strong>Test Sign Guestbook </strong></td>
    </tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form id="form1" name="form1" method="post" action="addguestbook.php">
    <td>`enter code here`
    <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
        <tr>
        <td valign="top">Comment</td>
        <td valign="top">:</td>
        <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
        </tr>
    </table>
    </td>
    </form>
    </tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr>
    <td><strong><a href="viewguestbook.php">View Notebook</a> </strong></td>
    </tr>
</table>

后端代码:

<?php
$host=***** 
$username=***** 
$password=**** This is all 100% correct, for sure.
$db_name=*****
$tbl_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");
$comments=$comment;
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(comment, datetime)VALUES('$comments', '$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();
?>

您可以使用$_GET$_POST方法检索comments。但是由于你使用POST方法,你需要像这样检索你的价值:

$comments=$_POST['comment'];

我同意使用:

$comments = $_POST['comment'];

另一件会让你的生活更轻松的事情是名为NOW()的内置函数,有关该函数的更多信息可以在这里找到:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

总的来说,只需确保创建一个链接到表单的结果或"帖子"的变量,然后可以在以后使用该变量,即当您需要将内容插入数据库时。