user3050963 user3050963 - 15 days ago 7x
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

$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
validation but don't understand why. Any suggestions?


Try this :

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

Hope this help u.