[英]PDO inserting the same data twice
I have got this Jquery Ajax code 我有这个Jquery Ajax代码
$("body").on('keyup', '.add_thing_t', function(event) {
if(event.which==13){
var v=$(this).val();
$.ajax({
url: 'ajax.php',
data: "add_thing="+v,
success:function(a){
// alert(a);
}
})
}
});
And this PHP 而这个PHP
if (isset($_GET['add_thing'])) {
$Val=$_GET['add_thing'];
$query=$dbh->query("INSERT INTO Ttd (`Thing`) VALUES('$Val')");
$query->execute();
}
This code is working,but it always inserts the same data twice. 该代码有效,但始终将相同的数据插入两次。
->query
executes it one time, ->execute
does it a second time. ->query
执行一次, ->execute
第二次。 You need to remove the execute
. 您需要删除execute
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.