$(document).ready(function() {
"use strict";
var id_var = "<?php echo $id_question; ?>";
$("#option1").click(function() {
alert(id_var);
$.post('updateDatabase.php', {
id: id_var,
option: "option1_clicked"
});
});
<?php
$id = $_POST['id'];
$option = $_POST['option'];
$connection = mysqli_connect("localhost", "root", "" , "log_database");
if ($option == 'option1_clicked') {
$queryOption1 = "UPDATE `questions` SET `option1_clicked` = `option1_clicked` + 1 WHERE id='$id'";
$query_run_option1 = mysqli_query($connection,$queryOption1);
}
?>
When I enter in the id field of my $.post
an id from my database it updates correctly.
When I do an alert(id_var)
to check if the variable gets the correct value, it works.
So you would think (at least I do) when I put id_var
after id:
it will update my database but this doesn't work.
Why?