Jump to content

PLease Help me in this Error


Recommended Posts

<?php
require("config/config.php");
if(isset($_SESSION['username'])){
    
    $userLoggedIn = $_SESSION['username'];
    $user_detail = mysqli_query($con, "SELECT * FROM users WHERE username='$userLoggedIn'");
    $user = mysqli_fetch_array($user_detail);
    echo $user['First_Name'];
}    
?>

In the Same Page

line:33 -->     <?php echo $user['First_Name']?>

When i execute my code i show the error


Notice: Undefined variable: user in C:\xampp\htdocs\social\include\header.php on line 33

 

Link to comment
Share on other sites

18 hours ago, Ehsan_Nawaz said:

When i execute my code i show the error

Based on the code provided, $user is only being set if the SESSION variable for "username" is set. If you haven't already, I would check to see what that SESSION variable contains when you're getting the error.

It's difficult to tell how you should proceed with the information provided. In the end, you'll likely need to test whether $user is set before trying to use it. How you do that depends on the purpose of the page and how your script is set up.

Link to comment
Share on other sites

Try putting this bit of debugging code in your script right before your if() statement.  What does it produce when you run the script?

if(!isset($_SESSION))
{
    echo "Session was not started yet";    
}
else
{
    echo "Session data:<br>";
    echo "<pre>".print_r($_SESSION, true)."</pre>";
}

 

Link to comment
Share on other sites

Here is the config file code

 

<?php
ob_start();
session_start();
$timeOne = date_default_timezone_set("Europe/London");
$con = mysqli_connect("localhost","root","","social");
if(mysqli_connect_errno()){
    echo"Filled to connect";
}
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.