php - 根据 if else 条件更新行值

标签 php mysql sql if-statement

在 php 页面中,一旦我们点击“提交”按钮,我们就会在数据库中保存订单 ID,它工作正常......

enter image description here

要求:

如果付款方式为“货到付款”,那么我想将订单 ID 保存在 “awb_type : COD” 行中......否则保存在 “awb_type : PPD” 中> 行....

enter image description here

这是完整的代码,track.php:https://pastebin.com/zLjpee7A ,call.php:https://pastebin.com/4LkcxTYE

但是订单在表中更新了两次 - PPD 中的一行和 COD 中的一行

enter image description here

如果您需要更多信息,请告诉我......

更新2:

现在我尝试了下面的代码,但无论 payment_type 是什么,它仅保存在 awb_type 列中: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);
}

最佳答案

在我没有将 payment_type 与 order_id 绑定(bind)之前,以下代码对我有用:

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); 

关于php - 根据 if else 条件更新行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53447047/

相关文章:

php - Elasticsearch搜索在索引后延迟提取最新数据

php - 以编程方式从产品中删除类别

sql - 如何找到Oracle数据库中两条记录(两个不同列)之间的时间间隔(以分钟为单位)

sql - 尝试在 Access 中创建 View 给出 "Syntax error in CREATE TABLE statement"

php - 根据用户输入在 Laravel 中创建新表?

带有特征的 PHP 命名空间问题

mysql - MySQL 复制是否不同步?等待从 SQL 线程释放足够的中继日志空间

mysql - 如何选择表中出现次数最多的值?

sql - *在sql中是什么意思?

php - 如何包装正确准备好的语句并使用数组绑定(bind)实现 IN(?) 表达式?