简体   繁体   中英

PDO inserting the same data twice

I have got this Jquery Ajax code

$("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

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. You need to remove the execute .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM