ユーザーの入力後、送信せずにテキストがmysqlに自動更新されるテキストボックスを作成しています。問題は、テキストボックスがデータベースを更新しないことです。これは、以下のすべての意見を参照して編集したものです。まだ問題がありますが、何も表示されないよりはましです。ありがとうございます。
ここにテキストボックスの入力があります
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);
?>