I'm a beginner in PHP. I have an error which is
Undefined index: user_id on line 7.
The page is work but when I reload it's show me this error and gone. How can I fix it ?
<?php
if (isset($_GET['username']) === true && empty($_GET['username']) === false) {
include 'core/init.php';
$username = $getFromU->checkInput($_GET['username']);
$profileId = $getFromU->userIdByUsername($username);
$profileData = $getFromU->userData($profileId);
$user_id = $_SESSION['user_id'];
$user = $getFromU->userData($user_id);
if (!$profileData) {
header('Location: index.php');
}
}
?>
The error on line 7 which means this line
$user_id = $_SESSION['user_id'];
But I don't see any problem ? Someone help me please!``
The file of project: profile.php
this is init.php
<?php
include 'database/connection.php';
include 'classes/user.php';
include 'classes/tweet.php';
include 'classes/follow.php';
global $pdo;
session_start ();
$getFromU = new User($pdo);
$getFromT = new Tweet($pdo);
$getFromF = new Follow($pdo);
define("BASE_URL", "http://localhost/twitter/");
?>