Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Notice: Undefined index

    Hi
    im having a little problem that i cant seem to fix. What im trying to do is grab the firstname from the database using sessions, i can get it to grab the username id and email but when i try to grab the firstname i get Notice: Undefined index any help would be great.

    private.php
    PHP Code:
    WORKING!!
    <?php
    require("config.php");
    if(empty(
    $_SESSION['user']))
    {
    header("Location: login.php");
    die(
    "Redirecting to login.php");
    }
    ?>
    Hello <?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES'UTF-8'); ?><br />

    NOT WORKING!!
    <?php
    require("config.php");
    if(empty(
    $_SESSION['user']))
    {
    header("Location: login.php");
    die(
    "Redirecting to login.php");
    }
    ?>
    Hello <?php echo htmlentities($_SESSION['user']['firstname'], ENT_QUOTES'UTF-8'); ?><br />
    config.php code
    PHP Code:
    <?php
    ob_start
    ();
    $username "xxxx";
    $password "xxxx";
    $host "localhost";
    $dbname "xxxx";
    $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
    try
    {
    $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8"$username$password$options);
    }
    catch(
    PDOException $ex)
    {
    die(
    "Failed to connect to the database: " $ex->getMessage());
    }
    $db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODEPDO::FETCH_ASSOC);
    if(
    function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
    {
    function 
    undo_magic_quotes_gpc(&$array)
    {
    foreach(
    $array as &$value)
    {
    if(
    is_array($value))
    {
    undo_magic_quotes_gpc($value);
    }
    else
    {
    $value stripslashes($value);
    }
    }
    }
    undo_magic_quotes_gpc($_POST);
    undo_magic_quotes_gpc($_GET);
    undo_magic_quotes_gpc($_COOKIE);
    }
    header('Content-Type: text/html; charset=utf-8');
    session_start();
    ?>

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    Where are you setting the session variables?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    Where are you setting the session variables?
    Hi
    i feel so dumb right now lol i forgot to add it to the session variables. Have not been coding for some time now lol thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •