因此,我試圖將評論推送到我的數據庫(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