user3050963 user3050963 - 2 months ago 9
Ajax Question

After successful ajax POST operation nothing happens in the database

I've checked for duplicates and none of them are strictly related to this problem.

I have the following javascript code

var value = $.ajax({
type: "POST",
url: "bank.php",
data: {sum:money},
cache: false,
async: true
}).done(function() {
console.log( "success" );
}).fail(function() {
console.log( "error" );
});


and php in bank.php

if(isset($_POST['sum']))
{
$money = mysql_real_escape_string($_POST['sum']);
$query = "UPDATE banks SET currency = 1 WHERE amount = '.$money.'";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}


I receive in the browser console "success" for the ajax operation but nothing happens in the database. Take note that "currency" is a tinyint(1) and amount is an int(10) [I'm using sql tables as you might have guessed]. What am I doing wrong? (bank.php also includes the header to link to my database, so that's not the problem because I tested others queries there).

I believe the code isn't going through the
if(isset($_POST['sum']))
validation but don't understand why. Any suggestions?

Answer

Try this :

$query = "UPDATE banks SET currency = 1 WHERE amount = ".$money.";

Hope this help u.