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(){
counterConfirm++;
if (counterConfirm == 1) {
$.ajax({
type: "POST",
url:"../php_includes/game_calc.php",
data: {"insert": counterConfirm},
success: function(data){
console.log("successful");
console.log(data);
}
})
}
});
And here's the PHP code:
include('openconn.php');
if(isset($_POST["insert"])) {
addInsert($_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 succesful
string on my console, but my database isn't updated.