This question already has an answer here:
When I run my PHP code, it gives me the following error:
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given
What is causing this?
Here is the code in which the query is executed:
class accounts {
public function check_login($a,$b)
{
$conn = mysqli_connect("localhost", "username", "pw", "dbname");
$result = mysqli_query($conn, "select * from members WHERE username='$a' and password='$b'");
if (mysqli_num_rows($result) == 0) {
$arr = array("message" => "fail");
} else {
$row=mysqli_fetch_assoc($result);
$arr=array("message"=>"success");
}
return $arr;
}
}
?>
and here is the code that calls that function:
if (isset($_POST['Login'])){
$ra=$obj->check_login($_POST['myusername'],$_POST['mypassword']);
if ($ra['message']=="success") {
$_SESSION['x']=$ra['myusername'];
$_SESSION['y']=$ra['mypassword'];
header("location:index.php");
} else {
echo "<center><font color='red'><b>Wrong Username or Password</center></font></b>";
Any help would be very much appreciated.
</div>