我正在尝试编写将编辑 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/