vendredi 23 novembre 2018

update row value based on if else condition

In php Page once we click on "Submit" button , in database we are saving order id, its working fine....

enter image description here

Requirement :

If payment is "Razorpay" , than i want to save order id in "awb_type : PPD" row.... otherwise in "awb_type : COD" row....

enter image description here

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

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

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

$awb = $resultc[0]['awb']; 
$sqld = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awb."' limit 1"; 
$resultd = $db_handle->runSelectQuery($sqld);

$awba = $resultca[0]['awb'];
$sqlda = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awba."' limit 1"; 
$resultda = $db_handle->runSelectQuery($sqlda);

here is full code , track.php : https://pastebin.com/zLjpee7A , call.php : https://pastebin.com/d7LjDkCK

But orders are updating twice in table - one row in PPD & one in COD

enter image description here

I tried if else condition so that it should execute only one time, but still its executing two times, but this time both rows updating in either PPD / COD

enter image description here

$payment_type='';
$sqle="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resulte = $db_handle->runSelectQuery($sqle);
if($payment_type=="Cash on Delivery")
{
$resultd = $db_handle->runSelectQuery($sqld);
}
else
{
$resultda = $db_handle->runSelectQuery($sqlda);
}

Please let me know if you need more information....

Aucun commentaire:

Enregistrer un commentaire