Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre><?php

session_start();
$con= mysqli_connect("localhost","root","","phplogin1");
$email = $_POST['email'];
$password = $_POST['password'];
$sql="SELECT * FROM 'accounts' where email='$email' and password ='$password'";

$result=mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);


if ($row)
{
    
    header("location:home.php");
   $_SESSION['email'] = $_POST['email'];
   $_SESSION['loggedin'] = TRUE;
}
 else {
echo"Invalid";
//header ("refresh:2;url=login.php");
}
?>


What I have tried:

It is a very simple login page to for my application. I will develop the secure version later on. I having the error mysqli_fetch_array() expects parameter 1 to be mysqli_result when the user enter the correct email and password. The database will have the column username,password,email,image,address
Posted
Updated 7-Sep-20 21:39pm
v2

1 solution

Quote:
mysqli_num_rows() expects parameter 1 to be in mysqli_result,bool given in

As per documentation of PHP: mysql_query - Manual[^] - when the query statement fails the call returns the boolean value FALSE.
It means, your query is returning FALSE and you expect a different type and have code based on it.
PHP
$row = mysqli_fetch_array($result);

Above, fetch query would not accept false as input parameter (which seems to be the value of $result). You need to act based on the $result value. Like:
PHP
$rows = mysqli_num_rows($query);
if($rows == 1){
    // login found
}
else
{
    // no user
}

OR
PHP
if($row){
            // login found
        }
    } else{
  // no user
}


Have a look at this to try and learn: How to Create A Simple Login Form in PHP & MySQLi Tutorial ~ Softaox[^]
Simple User Registration & Login Script in PHP and MySQLi | All PHP Tricks[^]
 
Share this answer
 
v4
Comments
syed mustafa 2021 7-Jun-21 14:46pm    
$res = mysqli_fetch_array($query);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900