使用一个按钮创建两个DB更新和一个插入

I have been fighting with this. Hope this helps others as well. I have a page for an invoice display, it populates and displays perfectly, I want to do major DB changes with the "Pay" button.

If there is an OrderIn_id, it should update the order_instate column of paid to "Yes", or if there is an OrderOut_id it should update the order_outstate column of paid to "Yes", there can be an instance where there is one or the other Id's or could have both. Then it inserts values into an invoice table.

The insert works perfectly, I am not getting any error messages, and it goes to the next page as if it all works, but it does NOT update the order tables to paid = "Yes", it keeps the field the same. Can you advise me of what I may not be seeing in this code. This is the php code that is called when the submit button is pressed.

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST') {

    if(isset($row['orderIn_id'])) {
        $orderIn_id = $row['orderIn_id'];
        $ip_id = $row['ip_id'];
        $orderIn_quantity = $row['orderIn_quantity'];
        $orderIn_total = $row['orderIn_total'];
        $orderIn_paid = "Yes";

    $changeVal="UPDATE order_instate
                 SET user_id = '$user_id', ip_id = '$ip_id', orderIn_quantity = '$orderIn_quantity', orderIn_total = '$orderIn_total',  
                 orderIn_paid = '$orderIn_paid'
                 WHERE orderIn_id = '$orderIn_id'; " ; 

    $changeCheck=mysqli_query($dbhandle, $changeVal) 
                        or die(mysqli_error($dbhandle));
     }

    if (mysqli_affected_rows($dbhandle) == 1) {
        echo "<span class = 'errorlog'><br />The Order update was successful.<br /></span>";
    }

    if(isset($row2['orderOut_id'])) {           
        $orderOut_id = $row2['orderOut_id'];        
        $op_id = $row2['op_id'];
        $orderOut_quantity = $row2['orderOut_quantity'];
        $orderOut_total = $row2['orderOut_total'];
        $orderOut_paid = "Yes";

    $changeVals="UPDATE order_outstate
                 SET user_id = '$user_id', op_id = '$op_id', orderOut_quantity = '$orderOut_quantity', orderOut_total = '$orderOut_total',  
                 orderOut_paid = '$orderOut_paid'
                 WHERE orderOut_id = '$orderOut_id'; " ; 

    $changeCheck2=mysqli_query($dbhandle, $changeVals) 
                        or die(mysqli_error($dbhandle));
    }

    if (mysqli_affected_rows($dbhandle) == 1) {
    echo "<span class = 'errorlog'><br />The Order update for out of state was successful. <br /></span>";
    }           

    $invoice_total = 0;
    $invoice_total = $gtotal;
    $invoice_shipped = "No";

    $add ="INSERT INTO invoice(user_id, invoice_total, invoice_shipped)
                VALUES ('$user_id', '$invoice_total', '$invoice_shipped')"; 

    $addCheck=mysqli_query($dbhandle, $add)
                        or die(mysqli_error($dbhandle)); 

    if($addCheck == NULL){
            echo "<span class = 'errorlog'><br />Your Payment was not successful. Please try again. <br /></span>";
            } else {
            header("location: userOrders.php");
            }
    }
?>