im trying to get values from a database but it shows “mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\kcms\a.php on line 15” error. Can someone help me?
<?php
//include 'functions.php';
$con = mysql_connect("localhost","Akash","kaka123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$student = false;
$teacher = false;
$office = false;
$username = 56;
$password = 38;
$query= "SELECT Register_no , Password FROM student profile WHERE Register_no=$username AND Password=$password" ;
$result = mysql_query($query, $con);
$prnt=mysql_fetch_array($result);
if ($prnt[0]==NULL)
{
$auth=0;
}
else
{
$auth=1;
$student= true;
}
if ($auth==0)
{
$query= "SELECT Staff_id , Password FROM staff profile WHERE Staff_id=$username AND Password=$password" ;
$result = mysql_query($query, $con);
$prnt=mysql_fetch_array($result);
if ($prnt[0]=NULL)
{
$auth=0;
}
else
{
$auth=1;
$teacher = true;
}
}
if ($auth==0)
{
$query= "SELECT Staff_id , Password FROM office staff WHERE Staff_id=$username AND Password=$password" ;
$result = mysql_query($query, $con);
$prnt=mysql_fetch_array($result);
if ($prnt[0]==NULL)
{
$auth=0;
}
else
{
$auth=1;
$office = true;
}
}
echo $username;
?>
can someone please reply soon?
The error message is actually very precise and helpful.
mysql_fetch_array()is being called with a boolean value where a resource is expected. If you look at the documentation formysql_query(), you will see that it returnsFALSEon failure, which is a boolean. This value is stored in$result, which is then passed tomysql_fetch_array(). So, an error occurs with your SQL query. You can check the error like this:That being said, you have a space between “student” and “profile” which should not be there. You probably meant to put an underscore there?
Also, please consider using MySQLi or PDO instead as the mysql_* extension is deprecated. I am merely name dropping here, so please take the time to read about these.