简体   繁体   English

成功执行ajax POST操作后,数据库中无任何反应

[英]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 我有以下javascript代码

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 php在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. 我在浏览器控制台中收到Ajax操作的“成功”消息,但是数据库中没有任何反应。 Take note that "currency" is a tinyint(1) and amount is an int(10) [I'm using sql tables as you might have guessed]. 请注意,“ currency”是tinyint(1),amount是int(10)[正如您可能已经猜到的,我正在使用sql表]。 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). (bank.php还包括链接到我的数据库的标头,所以这不是问题,因为我在那里测试了其他查询)。

I believe the code isn't going through the if(isset($_POST['sum'])) validation but don't understand why. 我相信代码不会通过if(isset($_POST['sum']))验证,但不明白为什么。 Any suggestions? 有什么建议么?

Try this : 尝试这个 :

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

Hope this help u. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM