vendredi 3 avril 2015

else part not executing in php if condition

I've got this project on DBMS. My form is working if I enter the correct username and password.. but it shows only a blank page when i enter wrong details.. It's not executing the else part.. It if part is working fine.. Can anyone help me.. I'm new to PHP.



<html>
<head>
<title></title>
</head>
<body>

<?php
include 'connection.php';
SESSION_START();
$user = $_POST['registeredEmail'];
$pass = $_POST['registeredpassword'];
$sql = "SELECT * FROM users WHERE email = '".$user."' and password = '".$pass."';";
$qry = mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_array($qry) or die(mysql_error());
if($result)
{
$_SESSION['UserName'] = $result['name'];
echo '<script type="text/javascript">';
echo 'alert("Sign In Successful");';
echo 'window.location.href = "sell.php";';
echo '</script>';



}
else
{
// header('Location: index.php');
echo 'sign in unsuccessful';
echo '<script type="text/javascript">';
echo 'alert("Sign In UnSuccessful. Either Email or password or both are wrong.. please try again or Sign Up");';
echo 'window.location.href = "index.php";';
echo '</script>';
}
?>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire