javascript - PHP 中的查询语句有未定义的参数

标签 javascript php mysql angularjs json

我正在尝试编写将编辑 SQL 数据库中的单个条目的代码,$num 是发票 ID 号,我必须错误地传递它,因为我的控制台显示 idinvoice 的未定义值,

现在控制台没有显示任何错误:/

Google 和 Stack 尚未取得太多成果,

这是我的 JavaScript

$scope.saveEdit = function($param){

    $scope.list2 = { };

        if($scope.who == 'Dealer'){ $scope.list2.billTo        = 'Dealer';             $scope.billTo        = ''; }
        else                      { $scope.list2.billTo        = 'Customer';           $scope.billTo        = ''; }
        if($scope.billStart)      { $scope.list2.billStart     = $scope.billStart;     $scope.billStart     = ''; }
        if($scope.customerName)   { $scope.list2.customerName  = $scope.customerName;  $scope.customerName  = ''; }
        if($scope.dealerName)     { $scope.list2.dealerName    = $scope.dealerName;    $scope.dealerName    = ''; }
        if($scope.item)           { $scope.list2.item          = $scope.item;          $scope.item          = ''; }
        if($scope.price)          { $scope.list2.price         = $scope.price;         $scope.price         = ''; }
        if($scope.qty)            { $scope.list2.qty           = $scope.qty;           $scope.qty           = ''; }
        if($scope.cost)           { $scope.list2.cost          = $scope.cost;          $scope.cost          = ''; }
        if($scope.contractTerms)  { $scope.list2.contractTerms = $scope.contractTerms; $scope.contractTerms = ''; }
                                    $scope.list2.per           = $scope.per;           $scope.per           = '0';

    $http.post('DealerRec/writeInvoice.php?$num='+$param+'&action=writeEdit', $scope.list2)
        .success(function(data){ console.log("Data Written"); console.log(data); })
        .error(function()      { console.log("Data Not Written");                });
}

这是我用于连接 SQL 的 php 文件

switch($_GET['action']){
case 'writeInvoice':
        writeInvoice();
        break;
case 'fetchInvoice':
        echo fetchInvoice($_GET['num']);
        break;
case 'saveEdit':
        writeEdit($_GET['num']);
        break;
}

function writeEdit($num){

$data = json_decode(file_get_contents("php://input"));
$customerName  = $data->customerName;
$dealerName    = $data->dealerName;
$billTo        = $data->billTo;
$billStart     = substr($data->billStart,0,10);
$contractTerms = $data->contractTerms;
$item          = $data->item;
$price         = $data->price;
$qty           = $data->qty;
$per           = $data->per;
$cost          = $data->cost;

$qry = "UPDATE  invoice
        SET
          customerName  = '{$customerName}',
          dealerName    = '{$dealerName}',
          billTo        = '{$billTo}',
          billStart     = '{$billStart}',
          contractTerms = '{$contractTerms}',
          item          = '{$item}',
          itemPrice     = '{$price}',
          quantity      = '{$qty}',
          cost          = '{$cost}',
          sharePercent  = '{$per}'
              WHERE idInvoice ='{$num}'";

echo ($qry);

$qry_res = new Query($qry);
if ($qry_res) { $arr = array('msg' => "Invoice edited successfully!!!", 'error' => ''); }
else          { $arr = array('msg' => "", 'error' => 'Error in inserting record');      }
}

最佳答案

解决办法如下

改成这个

    $http.post('DealerRec/writeInvoice.php?action=saveEdit', $scope.list2)
         .success(function(data){ console.log("Data Written"); console.log(data); })
         .error(function()      { console.log("Data Not Written");                     });
}

还有这个

case 'saveEdit':
        saveEdit();
        break;

最后是这个

$price         = $data->price;
$qty           = $data->qty;
$per           = $data->per;
$cost          = $data->cost;
$num           = $data->idInvoice; <----------------------

这些功能现在可以使用了。谢谢大家的帮助。

关于javascript - PHP 中的查询语句有未定义的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34618735/

相关文章:

javascript - requestAnimationFrame 没有取消

javascript - 模拟点击material-ui切换组件测试

php - 使用mysql查询与php比较数据

python - 对 SQL 结果进行排序以提高可读性?

javascript - xmlhttprequest 和 set-cookie & cookie

php - Facebook 应用取消授权回调 URL

php - PDO(PHP 数据对象)的缺点

mysql - 尝试为我的广告创建表格时出现代码错误

python - 如何使用 Python 从 Bash 提示符中捕获用户输入

javascript - 需要javascript中最接近的整数值