我需要使用AJAX將用戶輸入註釋立即保存到數據庫。 這是評論框。使用AJAX將數據記錄到數據庫
<div class="comment">
<form action="comment.php">
<textarea cols="35" name="comments"> Give us comment </textarea>
<input type="button" value="comment" onclick="ajaxFunction()">
</form>
</div>
這是PHP代碼
<?php
$link = mysql_connect("localhost","root","");
mysql_select_db("continental_tourism");
$comments = $_POST['comments'];
if($comments == "")
echo "Please type your comment";
else
{
$query = "insert into comment(comment) values('$comments') ";
mysql_query($query);
}
return;
?>
我需要知道應如何改變。 謝謝
我認爲看到'ajaxFunction()'是必要的。另外,如果你想讓人們爲你丟桌子,只需要問。 SQL注入不應該是這麼簡單。請查看準備好的陳述。 – Dan 2012-04-20 01:55:59
你需要發送數據在ajaxfunction() – Satya 2012-04-20 01:56:28
你能包括ajaxFunction()的代碼嗎?一般來說,你可以看看像prototype或jQuery這樣的框架。 – 2012-04-20 02:00:45