dougou7782 2019-03-30 08:55
浏览 49
已采纳

标头位置不起作用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>";  
     }
    ?>
  • 写回答

1条回答 默认 最新

  • dongtan3306 2019-03-30 09:17
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环