I have a simple login module wherein I enter login info to a database. After that, I use another file, loginauth.php which validates the login info. However, I am getting the else statement executed. Can somebody point out what's wrong.
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password']))
{
$userid = trim($_POST['userid']);
$password = trim($_POST['password']);
$con = new mysqli("internal-db.s110820.gridserver.com","db110820","Solved!2$$");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$query = "SELECT * from Login WHERE trim(email) = '$userid' and trim(password) = '$password'";
$result = $con->query($query);
if ($result->num_rows)
{
$_SESSION['valid_user']=$userid;
}
$con->close();
}
?>
<html>
<body>
<h1>Home Page<h2>
<?php
if (isset($_SESSION['valid_user']))
{
echo 'You are logged in as : '.$_SESSION['valid_user'].' <br/>';
echo '<a href = "logout.php">Log out</a><br>';
}
else
{
if (isset($userid))
{
echo 'Could not log you in . <br/>';
}
}
?>
</body>
</html>