Jump to content

Undefined index on $_SESSION


Moorcam
Go to solution Solved by Moorcam,

Recommended Posts

Howdy folks,

 

This is beating me to death very slowly.

 

I have set the sessions but one in particular is giving me an undefined index:

        <div class="modal-body">
            <?php
            if (isset($_SESSION['fname'])) {
                ?>
          <p><strong>First Name:</strong> <?php echo $_SESSION['fname']; ?></p>
          <?php
            }
            if (isset($_SESSION['lname'])) {
            ?>
          <p><strong>Last Name:</strong> <?php echo $_SESSION['lname']; ?></p>
          <?php
            }
            if (isset($_SESSION['admin_email'])) {
            ?>
          <p><strong>Email:</strong> <?php echo $_SESSION['admin_email']; ?></p>
          <?php
            }
           if (isset($_SESSION['phone'])) {
            ?>
            <p><strong>Phone:</strong> <?php echo $_SESSION['phone']; ?></p>
            <?php
           }
           ?>
        </div>

I am getting Undefined index 'phone' on this line:

<?php echo $_SESSION['phone']; ?>

This is where I have them set:

    $result = mysqli_query($mysqli, "SELECT user_id, admin_email, fname, lname, phone FROM admin_users WHERE admin_email = '" . $admin_email. "' and admin_password = '" .$admin_password . "'");

    if ($row = mysqli_fetch_assoc($result)) {
        $_SESSION['user_id'] = $row['user_id'];
        $_SESSION['admin_email'] = $row['admin_email'];
        $_SESSION['fname'] = $row['fname'];
		$_SESSION['lname'] = $row['lname'];
		$_SESSION['phone'] = $row['phone'];
        header("Location: index.php");
    } else {
        $errormsg = "Incorrect Email or Password Combination!";
    }
}
$mysqli->close();
?>

All other variables are showing without issue. Just that one.

Any ideas before I throw a tanty?

Edited by DanEthical
Link to comment
Share on other sites

I don't see anything that explains what you are seeing.

 

At the top of that script, after session_start(), var_dump($_SESSION); and see what it has in it.

It has all of them except for that one:

array(5) { ["user_id"]=> string(1) "2" ["admin_email"]=> string(23) "***" ["fname"]=> string(5) "***" ["lname"]=> string(9) "***" ["active"]=> NULL } 

Obviously I have replaced data with *** for privacy.

No idea where ["active"]=> NULL is coming from. It's not in the DB.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.