<?php
session_start();
$conn=mysqli_connect('localhost','root','');
$name=$_POST['name'];
$password=$_POST['password'];
$UserType=$_POST['cmbUser'];
if ($UserType=="Admin")
{
mysqli_select_db($conn,"prison") or die("Cannot connect to database");
$sql = "select * from Admin_Tbl where name='".$name."' and
password='".$password."'";
$result = mysqli_query($conn,$sql);
$records = mysqli_num_rows($result);
$row = mysqli_fetch_array($result);
if ($records==0)
{
echo $records;
echo '<script type="text/javascript">alert("Wrong UserName or Password");
window.location=\'login2.php\';</script>';
}
else
{
header("location:adminpanel.php");
}
mysqli_close($conn);
}
else if($UserType=="Police")
{
mysqli_select_db($conn,"prison") or die("Cannot connect to database");
$sql = "select * from pol where name='".$name."' and
password='".$password."'";
$result = mysqli_query($conn,$sql);
$records = mysqli_num_rows($result);
$row = mysqli_fetch_array($result);
if ($records==0)
{
echo $records;
echo '<script type="text/javascript">alert("Wrong UserName or Password");
window.location=\'login2.php\';</script>';
}
else
{
$_SESSION['ID']=$row['Station_Id'];
$_SESSION['Name']=$row['Station_Name'];
header("location: officerpanel.php");
}
mysqli_close($conn);
}
?>
This is the login code...the admin login works fine...but the police login always gives wrong username or password error even if it is correct!!! I have inserted a new user to the 'pol' table using stored procedure....The user gets added to the table but I am not able to login with that username and password..please help!!