我正在创建一个文本框,其中的文本会自动更新到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'“'缺少'$查询=” ...' –