从mysql db

时间:2015-07-07 13:20:55

标签: javascript php jquery ajax cordova

我打开一个支付服务的inappbrowser窗口。付款完成后,我的数据库中的成功条目将被更新。

用户表 - 像

这样的行
ID - USERNAME - VIPSTATUS - CALLSTATUS

支付后vipstatus和callstatus变为“1”。当关闭inappbrowser时,我想从用户获取vipstatus和callstatus的新数据,并覆盖现有的localstorage items callstatus和vip状态。用户名作为用户名保存在localstorage中。 我猜我的ajaxcode是错误的,因为它不起作用,它甚至不加载脚本。

我的Ajax代码

$(document).ready( function() {
                  $("#paybutton").click(function() {
                                        var params = "projectpaymentoption=1195&id=",
                                        usernamepay = window.localStorage.getItem("username"),
                                        paymenturl = params + usernamepay;

                                        $.ajax({
                                               type: 'POST',
                                               url: 'http://www..de/phone/encode.php',
                                               data: $.param({"paymenturl": paymenturl}),
                                               success: function(result) {
                                               var paybrowser = window.open(result,'_blank','location=no','closebuttoncaption=Zurück');

                                               paybrowser.addEventListener('exit',function(event) {


                                               $.ajax({
                                               type: 'POST',
                                               url: 'http://www..de/update.php',
                                               data: $.param({"username": username}),
                                               success: function(data) {
                                               window.localStorage.setItem("vipstatus", data[2]);
                                               window.localStorage.setItem("callstatus",data[3]);
                                      }
                         });
                  }

我的UPDATE.PHP代码

<?php 


  $dbhost = "blabla";
  $dbuser = "blabla";
  $dbpass = "blabla";
  $dbname = "blabla";
  $tableName = "user";


  print_r($_POST);
  $user = $_POST['data']['username'];
  print PHP_EOL . $user . PHP_EOL;

  $con = mysqli_connect($dbhost,$dbuser,$dbpass);
  $dbs = mysqli_select_db($dbname, $con);
  $result = mysqli_query("SELECT user$ FROM $tableName");         
  $array = mysqli_fetch_row($result);           
  $conn->close();
  ?>

2 个答案:

答案 0 :(得分:1)

<?php 

  $dbhost = "blabla";
  $dbuser = "blabla";
  $dbpass = "blabla";
  $dbname = "blabla";
  $tableName = "user";

  $con = mysqli_connect($dbhost,$dbuser,$dbpass);
  $dbs = mysqli_select_db($con, $dbname);

  print_r($_POST);
  $user = mysqli_real_escape_string($con, $_POST['data']['username']);
  print PHP_EOL . $user . PHP_EOL;

  $result = mysqli_query($con, "SELECT $user FROM $tableName");         
  while ($array = mysqli_fetch_row($result)) {
  echo $array['vipstatus'];

  echo $array['callstatus'];
  }           
  $conn->close();
  ?>

修正了你的mysqli_ *查询。在$result$dbs

答案 1 :(得分:1)

您的Javascript代码无效Javascript。它错过了一些结束括号。试试这个:

$(document).ready(function() {
    $("#paybutton").click(function() {
        var params = "projectpaymentoption=1195&id=",
            usernamepay = window.localStorage.getItem("username"),
            paymenturl = params + usernamepay;

        $.ajax({
            type: 'POST',
            url: 'http://www..de/phone/encode.php',
            data: $.param({
                "paymenturl": paymenturl
            }),
            success: function(result) {
                var paybrowser = window.open(result, '_blank', 'location=no', 'closebuttoncaption=Zurück');

                paybrowser.addEventListener('exit', function(event) {

                    $.ajax({
                        type: 'POST',
                        url: 'http://www..de/update.php',
                        data: $.param({
                            "username": username
                        }),
                        success: function(data) {
                            window.localStorage.setItem("vipstatus", data[2]);
                            window.localStorage.setItem("callstatus", data[3]);
                        }
                    });
                });
            }
        });
    });
});