www.webdeveloper.com
Results 1 to 4 of 4

Thread: Undefined index errors....

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    57

    Undefined index errors....

    I just learned new errors about the Undefined index but at this time i just can't figure out how to solve this, i got error said

    Notice: Undefined index: userid in C:\VertrigoServ\xxx \login.php on line 104

    which is the codes showed

    Code:
    <?php
    $nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
    $nb_new_pm = $nb_new_pm['nb_new_pm'];
    ?>
    and other one in same error online 112 showed

    Code:
    <a href="list_pm.php">Your messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Logout</a>)
    after I put ini_set('display_errors','Off'); to remove error notice but is did not remove.

    Does anyone know what the problem relate to undefined index...

    please help thanks.

    AM

  2. #2
    Join Date
    Apr 2013
    Posts
    5
    You get undefined index errors when the index does not exist.

    Where are you setting $_SESSION['userid']? Have you initialized the session on your login.php file?
    Code:
    <?php
    if (!isset($_SESSION['userid'])) {
        die("SESSION HAS NOT BEEN INITIALIZED CORRECTLY OR userid HAS NOT BEEN SET");
        // If it ever gets in here, you need to clean up either the beginning of this page OR the place where you're supposed to be setting $_SESSION['userid'] at.
    }
    // Since if it ever gets here it means $_SESSION['userid'] is set, it is safe to ask for it in the query. It will not throw errors.
    $nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
    $nb_new_pm = $nb_new_pm['nb_new_pm'];

  3. #3
    Join Date
    Aug 2006
    Posts
    57
    yes i have initialized the session, please see the code where i put on the top of same page.

    Code:
    <?php
    //This page let log in
    include('config.php');
    if(isset($_SESSION['username']))
    {
    	unset($_SESSION['username'], $_SESSION['userid']);
    	setcookie('username', '', time()-100);
    	setcookie('password', '', time()-100);
    	ini_set('display_errors','Off');
    ?>
    one thing is works great in server but in local pc I'm getting same errors.

    Any idea ! please help thanks.

    AM

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    set your error reporting like this error_reporting(E_ERROR|E_WARNING); as very first statement of your config.php
    for more read here
    http://notesofgenius.com/how-fix-php...defined-index/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles