Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php
if(isset($_POST['login']))
{
	$username = $_POST['username'];
	$password = $_POST['password'];
	
	if(empty($username) or empty($password))
	{
	echo "fill the empty fields";
	exit();
	}
	
	if(isset($_POST['re']))
	{
		$re = "on";
	} 
	else 
	{
	$re = "";
	}
		
	$query = mysqli_query($con, "SELECT COUNT (*) FROM 'admin' WHERE username='$username' AND password='$password'");
	
	if (!$query || mysqli_num_rows($query) == 0)
	{ echo "very worng";
		}
	
	if(mysqli_num_rows($query) == 1);
	{
		
		// login user in
		if($re == "on")
		{ // remember me on
		setcookie("username",$username,time() + (86400 * 10));	
		}else
		{ // remember me not checked 
		session_start();
		$_SESSION["username"] = $username;
		}
		echo "user logedin";
		exit();
	}
	echo "invablid username or password";
	exit();
	
}
?>


What I have tried:

unable to understand, checked database and syntex phres
Posted
Updated 28-Jan-17 5:22am
Comments
CHill60 28-Jan-17 10:40am    
There is either a problem with your sql query or it is not returning any data. Check for success before using the result in any further code.
As an aside, you should NOT be storing passwords in plain text like this.

1 solution

This
mysqli_num_rows($query) 
expected
$query
to be a result set, but it turned out to be a boolean false. PHP: mysqli_result::$num_rows - Manual[^]. Try improving your code like this:
if (!$query) { 
	echo("Error description: " . mysqli_error($con));
} else if(mysqli_num_rows($query) == 1){
    // omitted
} else {
   echo "invablid username or password";
}
 
Share this answer
 

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