I am making a login/register system in php. For some reason in the login.php file i can not login any user. Bellow is the login.php file. I have the db connection and session start in connect.php file and any function needed in the functios.php file.
include("connect.php");
include("functions.php");
if(logged_in())
{
header("location: profile.php");
exit();
}
$error = "";
if(isset($_POST['submit']))
{
$email = mysqli_real_escape_string($con,$_POST['email']);
$password = mysqli_real_escape_string($con,$_POST['password']);
$result=mysqli_query($con,"SELECT id FROM users WHERE email='$email' and password='$password'");
$retrievePassword=mysqli_fetch_assoc($result);
$count=mysqli_num_rows($result);
if($count == 1)
{
$_SESSION['email']=$email;
if($checkBox="on")
{
setcookie("email",$email,time()+3600);
}
header("location: profile.php");
}
else
{
$error="Emai or Password is inccorect, check again!";
}
}
<div id="error"><?php echo $error;?></div>
<div id="link">
<a href="index.php">Register</a>
<a href="login.php">Login</a>
</div>
<div id="formDiv">
<form method="post" action="login.php">
<label>Email:</label><br>
<input type="text" name="email"><br><br>
<label>Password:</label><br>
<input type="password" name="password"><br><br>
<input type="checkbox" name="keep">
<label>Keep me logged in</label><br><br>
<input type="submit" name="submit" value="Login">
</form>
</div>
</div>
id: ". $row["id"]. " - Name: ". $row["email"]. " " . $row["password"] . "
"; } } else { echo "0 results"; } $con->close(); **bold**I did this just now and it shows everything, email id pass all that we need, so the query work fine, the hell is wrong then????????? – njazi Jul 19 '16 at 23:16