/    Sign up×
Community /Pin to ProfileBookmark

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:VertrigoServxxx 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’];
?>
[/CODE]

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>)[/CODE]

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@redmagebrApr 26.2013 — 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'];[/CODE]
Copy linkTweet thisAlerts:
@AlidadauthorApr 26.2013 — 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');
?>[/CODE]


one thing is works great in server but in local pc I'm getting same errors.

Any idea ! please help thanks.

AM
Copy linkTweet thisAlerts:
@ZABIMay 02.2013 — 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-notice-undefined-index/
×

Success!

Help @Alidad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...