我在这里遇到错误,请帮我

时间:2018-07-27 07:16:49

标签: php mysql

<?php
     $conn=mysqli_connect("localhost","root","","telephasic");
     if(isset($_GET['role']))
     {
        $role1=$_GET['role'];
        $query = "SELECT * FROM register WHERE id='$role1'";
        while($row=mysql_fetch_object($query))
        {
            $role_var=$row->role;
            if($role_var=='1')
            {
                $role_state="NULL";
            } else {
                $role_state="0";
            }
            $update=mysql_query("update register set status='$role_state' where id='$role1' ");
            if($update)
            {
               header("Location:admin.php");
            } else {
               echo mysql_error();
            }
       }
?>
<?php } ?>

我在这里遇到错误,请帮助我

  

致命错误:未捕获错误:调用未定义函数   C:\ xampp \ htdocs \ telephasic \ action.php:7中的mysql_fetch_object()   跟踪:在C:\ xampp \ htdocs \ telephasic \ action.php中抛出#0 {main}   第7行

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码:

   <?php
         $conn=mysqli_connect("localhost","root","","telephasic");
         if(isset($_GET['role']))
         {
            $role1=$_GET['role'];
            $query = "SELECT * FROM register WHERE id='$role1'";
            $result=mysqli_query($conn,$query); // u need to execute query first!!
            while($row=mysqli_fetch_object($result))
            {
                $role_var=$row->role;
                if($role_var=='1')
                {
                    $role_state="NULL";
                } else {
                    $role_state="0";
                }
                $update=mysqli_query($conn, "update register set status='$role_state' where id='$role1' ");
                if($update)
                {
                   header("Location:admin.php");
                } else {
                   echo mysqli_error();
                }
           }
    ?>
    <?php } ?>