I am trying to do an UPDATE to a table in PHP while using jQuery Ajax. The jQuery Ajax code calls the php file where a function is executed.

That function makes an UPDATE query with mysqli_query method. However, it doesn't work.

I've tried multiple solutions and none of them worked. The status_player1 column is a VARCHAR(20) and the id column is INTEGER.

When making the exact output I get of the full query in my database manually it works.

Here's the jQuery code:

   counterConfirm = 0;
   $(document).on("click", "#confirmButton", function(){

        if (counterConfirm == 1) {
                type: "POST",
                data: {"insert": counterConfirm},
                success: function(data){

And here's the PHP code:


    if(isset($_POST["insert"])) {

    function addInsert($count) {
        $id = intval($_SESSION["game_id"]);

        if($count == 1) {
            $query = "UPDATE games SET status_player1='R' WHERE id='{$id}';";
            mysqli_query($conn, $query);
            echo $query;


After executing the code, I get the succesfulstring on my console, but my database isn't updated.

0 Answers