-4

//what is error on this code

<?php
$dbserver="localhost";
$dbuser="root";
$dbpwd="";
$dbname="sectinfo_aisect";

$cid= new mysqli($dbserver,$dbuser,$dbpwd,$dbname);

if($cid->error){
    die("Connection Faild:". $cid->error);
}

$userName='Devendra';
$result = $cid-> query("SELECT designation, FROM user WHERE subadmin= '22' and username='$userName' ");

$row = $result-> fetch_assoc($result);

echo $row['designation'];

?>

Fatal error: Call to a member function fetch_assoc() on a non-object in

YOG_PHP
  • 188
  • 1
  • 16

3 Answers3

1

Fatal error: Call to a member function fetch_assoc() on a non-object

this error is because there is a error in your query $mysqli->query()

for reference - mysqli_query()

To see if your queries are correct.

  • Echo them directly in your html

  • copy them and run them into phpmyadmin

  • it will be more clear what you get output from there (error/data)

Meenesh Jain
  • 2,532
  • 2
  • 19
  • 29
0

Now check with this

$result = $cid -> query("SELECT designation FROM user WHERE username= '". $adminName ."'"); if ($result) { $row = $result -> fetch_assoc(); echo $designation = $row['designation']; }

Nagarajbgk
  • 31
  • 1
0

Try this by editing your lines.

$result = $cid-> query("SELECT designation FROM user WHERE subadmin= '22' and username='".$userName."'");

$row = $result-> fetch_assoc();
Riken Shah
  • 87
  • 10