标头位置不起作用inventory_id有空错误

I have item_users table and field here

    userid  | user_type |inventory_id |com_code 
    ------------------------------------------
         1  |           |           4 |sffdfgfdg

I want to before update after select query. error geting Header location is not working becouse $inventory_id is empty.

 <?php
     include("myhomeportal/setting/config.php"); 

      $conform = $_GET['conform-email'];
      $sql = "UPDATE item_users SET com_code=NULL,type_login='user' WHERE com_code='$conform'";
      $result = mysqli_query($conn,$sql) or die(mysqli_error());


      $query = mysqli_query($conn, "SELECT * FROM item_users where com_code='$conform'");
      $row=mysqli_fetch_array($query);
      $inventory_id=$row['inventory_id'];

     if($row)
     {
        header("Location: category.php?inventory_id=$inventory_id"); 
    }
     else
     {
        $msgerr="Error ";           
        echo "<script type='text/javascript'>alert('$msgerr');</script>";  
     }
    ?>

I suppose the logic should be like this:

$conform = $_GET['conform-email'];
$query = mysqli_query($conn, "SELECT * FROM item_users where com_code='$conform'");
$row = mysqli_fetch_array($query);
if ($row) {
    // now update `com_code`
    $sql = "UPDATE item_users SET com_code=NULL, type_login='user' WHERE com_code='$conform'";
    $result = mysqli_query($conn, $sql) or die(mysqli_error());

    $inventory_id = $row['inventory_id'];
    header("Location: category.php?inventory_id=$inventory_id");
} else {
    // confirm code not found, show error
}