この更新ステートメントを使用しています
$sql = "update questions set response = ?, `check` = ? where questionID = ? && starID = ?";
$qc = $pdo_conn->prepare($sql);
$qc->execute(array($_GET['response'], $_GET['check'], $_GET['questionID'], $_SESSION['starid']));
しかし、応答値に の&
ような が含まれている場合pop and r&b
、データベースでは として終了しますpop and r
。
また、改行がある場合は、次のようにすべてのスペースが削除されます。
Bob
Jim
データベースで最終的にBobJim
データベースの応答タイプはvarchar(10000)
$_GET['response']
ここに値を取得するJavaScriptコードがあります
var html = '';
$(document).ready(function(){
$(".save_btn").live('click', function() {
$('.response').each(function(){
//alert($(this).attr('id'));
//alert($(this).val());
if ($(this).val() == '') {
html = $.ajax({
url: "response.php?questionID=" + $(this).attr('id') + "&response=" + $(this).val() + "&check=0",
async: false
}).responseText;
}
if ($(this).val() !== '') {
html = $.ajax({
url: "response.php?questionID=" + $(this).attr('id') + "&response=" + $(this).val($POST['response']) + "&check=1",
async: false
}).responseText;
}
});
alert(html);
location.reload();
});
})
この場合、if のこの部分が重要な部分です。
if ($(this).val() !== '') {
html = $.ajax({
url: "response.php?questionID=" + $(this).attr('id') + "&response=" + $(this).val($POST['response']) + "&check=1",
async: false
}).responseText;
}
これを修正する方法についてのアイデアはありますか?