Php 创建评论框;文本正文无法转发
我正在尝试在网站上创建一个评论部分。我尝试使用的页面仅限于必需品。我的问题是注释主体没有被转发到我设置的表中。不过,日期会被发送和存储。我已经把代码贴在下面了。我已经看了这段代码一段时间了,开始感到沮丧。研究没有结果。我把这件事交给你们,作为我的最后手段。谢谢你的帮助和指导 前端代码:Php 创建评论框;文本正文无法转发,php,html,Php,Html,我正在尝试在网站上创建一个评论部分。我尝试使用的页面仅限于必需品。我的问题是注释主体没有被转发到我设置的表中。不过,日期会被发送和存储。我已经把代码贴在下面了。我已经看了这段代码一段时间了,开始感到沮丧。研究没有结果。我把这件事交给你们,作为我的最后手段。谢谢你的帮助和指导 前端代码: <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <
<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> </td>
<td> </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();
?>
测试标志留言簿
`在这里输入代码`
评论
:
后端代码:
<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> </td>
<td> </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();
?>
您可以使用$\u GET
或$\u POST
方法检索注释。但由于您使用的是POST
方法,因此您需要如下方式检索您的值:
$comments=$_POST['comment'];
我同意使用:
$comments = $_POST['comment'];
另一个使您的生活更加轻松的功能是名为NOW()的内置函数,有关此函数的更多信息,请参见:
总的来说,只需确保创建一个链接到表单的结果或“post”的变量,该变量就可以在以后使用,即在需要将内容插入数据库时使用