I have this problem that if the item exist in the cart table, it will update quantity but if I add another item which doesn't exist, it doesn't work. If the cart table is empty it works, in short how could I insert another product which doesn't exist? Thanks in advance.
if(!empty($_POST["quantity"])) {
    $productByCode = $db_handle->runQuery("SELECT * FROM tblproduct WHERE code='" . $_GET["code"] . "'");
    $cart_item = $db_handle->runQuery("SELECT * FROM `cart`");
    if(!empty($cart_item)){
        $code = $_GET["code"];
        $query = "SELECT code FROM `cart` WHERE code='" . $_GET["code"] . "'";
        $quantityByCode = $db_handle->runQuery("SELECT * FROM cart WHERE code='" . $_GET["code"] . "'");
        $nQuan = $quantityByCode[0]["quantity"] + $_POST["quantity"];
        if($query = $code){
            $db_handle->runQ("UPDATE cart SET quantity = ".$nQuan." WHERE code='" . $_GET["code"] . "'");
        }else{
            $db_handle->runQ("INSERT INTO cart (`name`, `code`, `size`, `quantity`, `price`, `cond`)VALUES ('". $productByCode[0]["name"] ."', '". $productByCode[0]["code"] ."' ,'". $productByCode[0]["size"] ."',". $_POST["quantity"] .",". $productByCode[0]["price"] .",1)");
        }
    }else{
        $query="INSERT INTO cart (`name`, `code`, `size`, `quantity`, `price`, `cond`) VALUES ('". $productByCode[0]["name"] ."', '". $productByCode[0]["code"] ."' ,'". $productByCode[0]["size"] ."',". $_POST["quantity"] .",". $productByCode[0]["price"] .",1)";
                $is_query_successful=mysql_query($query);
    }
}
 
    