I'm expecting to see the data of a user after I login but it always show the warning, "Undefined array key "user_id" in C:\xampp\htdocs\farm-e-mart\home.php on line 5"
//home.php
<?php
include 'config.php';
session_start();
$user_id = $_SESSION['user_id'];
if(isset($_GET['logout'])){
unset($user_id);
session_destroy();
header('location:login_form.php');
}
?>
//login_form.php
<?php
@include 'config.php';
session_start();
if(isset($_POST['submit'])){
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$pass = md5($_POST['password']);
$cpass = md5($_POST['cpassword']);
$user_type = $_POST['user_type'];
$select = " SELECT * FROM user_form WHERE email = '$email' && password = '$pass' ";
$result = mysqli_query($conn, $select);
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_array($result);
if($row['user_type'] == 'admin'){
$_SESSION['admin_name'] = $row['name'];
header('location:farmersite.php');
}elseif($row['user_type'] == 'user'){
$_SESSION['user_name'] = $row['name'];
header('location:site.php');
}
}else{
$error[] = 'incorrect email or password!';
}
};
I don't know what to do and also I just started learning php, what can i do to fix this?