我的代码显示没有errmsg,但没有将任何数据插入数据库

So I am trying to make a simple e-commerce site. Once I submit the form (btn-submit), I am not able to insert any data to my database. Only the address and contact number verification works.

Here is my code:

    if ( isset($_POST['btn-submit']) ) {

    // clean user inputs 
    $oadd = trim($_POST['oadd']);
    $oadd = strip_tags($oadd);
    $oadd = htmlspecialchars($oadd);

    $contact = trim($_POST['contact']);
    $contact = strip_tags($contact);
    $contact = htmlspecialchars($contact);


    // address validation
    if (empty($oadd)) {
        $error = true;
        $oaddError = "Please enter a valid address.";
    } else if (strlen($oadd) < 5) {
        $error = true;
        $oaddError = "Please enter a valid address.";
    }

    // contact number validation
    if (empty($contact)) {
        $error = true;
        $contactError = "Please enter your contact number.";
    } else if (strlen($contact) < 7) {
        $error = true;
        $contactError = "Contact number must have atleast 7 digits.";
    } else if (!preg_match("/^[0-9 ]+$/",$lname)) {
        $error = true;
        $lnameError = "Please enter a valid contact number.";
    }

    // if there's no error, continue to place order
    if( !$error ) {
        $query = 'INSERT INTO cust_order(Order_Date, Order_Status, Order_Total , Address, Contact_No) VALUES (CURDATE(), "in process" , (SELECT SUM(p.Product_Price) FROM cart c, product p WHERE c.Prod_ID = p.Product_ID and c. User_ID = "'.$userRow['User_ID'].'"),"'.$oadd.'","'. $contact.'")';
        $res = mysql_query($query);

        if ($res) {
            $errTyp = "success";
            $errMSG = "Your order has been placed. To view the details, go to your order history";
            unset($oadd);
            unset($contact);
        } else {
            $errTyp = "danger";
            $errMSG = "Something went wrong. Please try again later.";   
        }   

    }

}

What could possibly be wrong with my code? I did similar queries in the other pages but this is the only one not working. Any help would be greatly appreciated! Thanks in advance!

Try to understand the code flow:

if( !$error ) {
    // This will only works when **$error is false and the not of false is true**, otherwise this block does not execute
}

So this code works only when there is no validation error occurs in your code and $error contains false

//$userRow is not define any where...
//to check error occur or not :
echo $error;
if(!$error)
{
    echo "IN IF";
    //also go with die..
    $res = mysql_query($query) or die();
}
else
{
    echo "IN ELSE";
}