I have the following script:
$(function (){
$('.press_me').click(function(){
var request = $.ajax({
type: "POST",
url: "counter.php"
});
request.done(function( msg ) {
alert('Success');
return;
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
});
});
and counter.php:
<?php
// Connection to database
$connection=mysqli_connect("host","user","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo 'NOT_OK';
//echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Increasing the current value with 1
mysqli_query($connection,"UPDATE table SET amount = (amount + 1) WHERE ID='1' ");
mysqli_close($connection);
echo 'OK'; ?>
1.In order to see the updated value, I have to refesh the page, which i believe it means that the ajax is not working asynchornously, and that's what i would want.i tried everything with the async parameter but i failed.
2.What update clause should i use so as to update each row separately, as the code in this state updates only one row or if i omit the where clause, it updates all of them. Can anyone help me?