0
<?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 } ?>

I am getting error here so help me please

Fatal error: Uncaught Error: Call to undefined function mysql_fetch_object() in C:\xampp\htdocs\telephasic\action.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\telephasic\action.php on line 7

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
Thakur
  • 13
  • 4

1 Answers1

1

Try with this code:

   <?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 } ?>
MorganFreeFarm
  • 3,811
  • 8
  • 23
  • 46