I've been trying to redirect the user to the Userpanel.php page after a successful login, but header() method doesnt work in the if condition.
Here is the code:
<?php
$db_host="localhost";
$db_name="researchblog";
$db_user="root";
$db_pass="";
$conn=mysqli_connect($db_host, $db_user, $db_pass);
mysqli_select_db($conn,$db_name);
if(isset($_POST['username']))
{
$uname=$_POST['username'];
$password=$_POST['password'];
$sql="select * from users where username='".$uname."' AND password ='".$password."'";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result)==1)
{
header("location:Userpanel.php");
}
else
{
echo "<script> alert('Failed to Login') </script>";
}
}
?>