<?php
session_start();
// Including header/ conifg file.
include("include/header.php");
if (isset($_POST['login']))
{ // Check login is submit or not.
$email = $_POST['user_name'];
$password = $_POST['password'];
$query = "SELECT `id`,`email_id`, `password`, `first_name`,`roles` FROM tbl_registration WHERE email_id='" . $email . "' AND password='" . $password . "'";
$result = mysqli_query($conn, $query);
if ($num > 0)
{
$row = mysql_fetch_assoc($result);
if ($row['role'] == 1) {
$_SESSION["user_id"] = $row["id"];
$_SESSION["first_name"] = $row["first_name"];
$_SESSION["email_id"] = $row["email_id"];
header("Location: admin/index.php");
}
else {
$_SESSION["user_id"] = $row["id"];
$_SESSION["first_name"] = $row["first_name"];
$_SESSION["email_id"] = $row["email_id"];
header("Location: index.php");
}
}
}
?>
It seems like your if-statement isn't running because the variable $num isn't set. You need to add:$num = mysqli_num_rows($result);
You have misspelled role and roles in if ($row['role'] == 1)
and column name `roles`
Substitute mysql with mysqli when fetching result, writing instead:$row = mysqli_fetch_assoc($result);
Make sure to provide information for $conn:$conn = mysqli_connect("host", "user", "pass", "db");
<?php
session_start();
// Including header/ conifg file.
include("include/header.php");
// Check login is submit or not.
if (isset($_POST['login']))
{
$conn = mysqli_connect("host", "user", "pass", "db");
if (mysqli_connect_errno()) {
printf('Connect failed: %s
', mysqli_connect_error());
exit();
}
$email = $_POST['user_name'];
$password = $_POST['password'];
$query = "SELECT `id`,`email_id`, `password`, `first_name`,`roles` FROM tbl_registration WHERE email_id='" . $email . "' AND password='" . $password . "'";
$result = mysqli_query($conn, $query);
$num = mysqli_num_rows($result);
if ($num > 0)
{
$row = mysqli_fetch_assoc($result);
if ($row['roles'] == 1) {
$_SESSION["user_id"] = $row["id"];
$_SESSION["first_name"] = $row["first_name"];
$_SESSION["email_id"] = $row["email_id"];
header("Location: admin/index.php");
}
else {
$_SESSION["user_id"] = $row["id"];
$_SESSION["first_name"] = $row["first_name"];
$_SESSION["email_id"] = $row["email_id"];
header("Location: index.php");
}
}
}
?>