<!DOCTYPE HTML>
<html>
<head>
<title>Sign-In</title>
</head>
<body id="body-color">
<div id="Sign-In">
<form method="POST" action="connectivity.php">
User <br><input type="text" name="user" size="40"><br>
Password <br><input type="password" name="pass" size="40"><br>
<input id="button" type="submit" name="submit" value="Log-In">
</form>
</fieldset>
</div>
</body>
</html>
The above is the html code of my form which I have used for simple user login.
<?php
define('DB_HOST', 'localhost:3306');
define('DB_NAME', 'sample');
define('DB_USER','user');
define('DB_PASSWORD','passwd');
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
function SignIn()
{
session_start(); //starting the session for user profile page
if(!empty($_POST['user'])) //checking the 'user' name which is from Sign-In.html, is it empty or have some text
{
$query = mysql_query("SELECT * FROM UserName where userName = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());
$row = mysql_fetch_array($query) or die(mysql_error());
if(!empty($row['userName']) AND !empty($row['pass']))
{
$_SESSION['userName'] = $row['pass'];
echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";
}
else
{
echo "SORRY... YOU ENTERED WRONG ID AND PASSWORD... PLEASE RETRY...";
}
}
}
if(isset($_POST['submit']))
{
SignIn();
}
?>
This is the php script I have used to verify a user's login. But the above php code responds correctly when I entered the correct username and password which is stored previously in database. But when I tried to enter the wrong username and password, the else part is not working. Instead it is showing a white screen. Where can I've made the mistake?
Can anyone help me in getting this problem fixed?