【发布时间】:2013-02-06 02:21:24
【问题描述】:
我正在使用这个更新语句
$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;
}
关于如何解决这个问题的任何想法?
【问题讨论】:
-
你可能应该看看你的
$_GET变量的实际值,这可能是他们搞砸的地方。 -
对于流行和 r&b,echo $_GET['response']; = 流行音乐和 r。尝试 post 而不是 get 并得到一个空值
-
因此,无论通过 GET 请求发送这些变量的任何内容都没有正确编码它们,因此应首先修复。
-
好的,我将编辑我的帖子以包含那段代码
标签: php sql line-breaks ampersand update-statement