根据if else条件更新行值

ar7v8xwq  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(305)

在php页面中一旦我们点击“提交”按钮,在数据库中我们正在保存订单id,其工作正常。。。。

要求:
如果付款是“货到付款”,那么我想将订单id保存在“awb\u type:cod”行。。。。否则在“awb\ U类型:ppd”行中。。。。

下面是完整的代码track.php:https://pastebin.com/zljpee7a ,call.php:https://pastebin.com/4lkcxtye
但是订单在表中更新了两次,一行在ppd,一行在cod

如果你需要更多的信息请告诉我。。。。
更新2:
现在我尝试了下面的代码,但不管是什么付款类型,它只保存在awb类型列:ppd行。。。。

$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1"; 
$resultc = $db_handle->runSelectQuery($sqlc); 

$sqld = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1"; 
$resultd = $db_handle->runSelectQuery($sqld);

$payment_type='';
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);

if($payment_type=="Cash on delivery")
{
$awb = $resultc[0]['awb']; 
$sqle = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awb."' limit 1"; 
$resulte = $db_handle->runSelectQuery($sqle);
}
else
{
$awba = $resultd[0]['awb'];
$sqlf = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awba."' limit 1";    
$resultf = $db_handle->runSelectQuery($sqlf);
}
bkhjykvo

bkhjykvo1#

在我没有将付款类型与订单id绑定之前,以下代码适用于我:

if(isset($_POST['order_id']) && $_POST['order_id']!='')
{ 
$order_id = $_POST['order_id'];  
$payment_type=$_POST['payment_type'];

$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);

if($payment_type=="Cash on delivery")
{
  $sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1"; 
}
else
{
  $sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1"; 
}

$resultc = $db_handle->runSelectQuery($sqlc);

相关问题