因此,我试图将评论推送到我的数据库(icposts
,下面),我没有得到任何结果。我可以拉和显示我直接插入到数据库表中的评论,但是当我尝试从html表单发送评论时,它似乎根本不起作用。将评论发送给我在本地主机上的数据库
<?php
$connect=mysqli_connect("localhost","root","");
$database=mysqli_select_db("icposts");
$username=$_POST['poster'];
$title=$_POST['postTitle'];
$body=$_POST['postText'];
$date=$_POST['currentDate'];
$submit=$_POST['submit'];
if($submit)
{
$query=mysql_query("INSERT INTO 'posts'('id', 'username', 'title', 'body', 'date') VALUES ('','$username','$title','$body','$date')");
}
?>
这里的表单的HTML,供参考:
<form name="input" action="comments.php" method="POST">
\t Username: <input id = "poster" type="text" name="poster"value="Guest" /><br>
\t Tite: <input id = "postTitle" type="text" name="postTitle" /><br>
\t Comment: <br> <textarea id = "postText" name = "postText"rows="4" cols="50"></textarea>
\t <input id = "submit" name = "submit" type="submit" value="Submit" />
\t <input id = "currentDate" name = "currentDate" type = "hidden" value = "" />
</form>
感谢您的帮助!我正在做这项工作,并不要求页面安全,但我会在未来的项目中记住SQL注入。 – 2014-12-03 21:09:46
不客气谢恩,很高兴得到了帮助。请记住标记为已解决,*欢呼声* – 2014-12-03 21:11:29