我正在創建一個文本框,其中的文本會自動更新到mysql後用戶類型和提交。現在問題是文本框不會更新數據庫。這是我參考下面的所有意見編輯的。仍然有一些問題,但比沒有顯示now.thanks好。使用jQuery更新文本框
這裏是文本框中輸入
echo "<td class=\"align-center\"><input type=\"text\" name=\"comment\" id=\"comment\" onKeyPress=\"getComment($id,this)\" /></td>";
這裏是我的javascript
function getComment(id, txt_box)
{
var value = txt_box.value;
$.ajax({
'url': 'updatecomment.php',
'data': {"id": id, "comment": value},
'success': function (response) {
console.log(response);
//TODO: use server response
}
});
}
和最後一個是updatecomment.php
<?php require_once("../includes/connection.php") ?>
<?php require_once("../includes/functions.php") ?>
<?php
$id =$_GET['id'];
$comment = $_GET['comment'];
$query = "UPDATE tblinternapplication SET comment = '".mysql_real_escape_string($comment) ."' WHERE id = $id";
$result = mysql_query($query, $connection);
?>
*旁註:*停止使用廢棄的'mysql_ *'功能。改用MySQLi或PDO。 – Raptor
雙QUOT'「'缺少'$查詢=」 ...' –