Page 1 of 1
undefined index
Posted: Fri Jun 28, 2002 3:35 am
by jayymz
why do I get an undefined index error when using this?
The idea is to use the variable $user in an insert query later on. The variable gets its info from a form post.
anyone know?
Posted: Fri Jun 28, 2002 3:38 am
by twigletmac
You get an undefined index error because $_POST['user'] has not been set.
Use,
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>;
to see what is in the $_POST array.
Mac
Posted: Fri Jun 28, 2002 7:03 am
by jason
Yes, you might want to lower your error_reporting() level, and turn it off E_ALL.
Posted: Fri Jun 28, 2002 7:15 am
by twigletmac
Changing your error reporting means that the error will still be occuring and the script still won't be working as you expect but you won't see an error message. I'm not sure how useful that is, having the highest level of error reporting means that misspelled variable names and one's that don't exist are highlighted so that you can debug more effectively.
Mac
Posted: Fri Jun 28, 2002 7:22 am
by jason
I know. I do it at work, but at the same time, the warnings it pops up aren't necessarily wrong, as long as I expect that sometimes $_POST['username'] won't be there. If my program understands that, then there is no problem.
Posted: Fri Jun 28, 2002 7:39 am
by twigletmac
Maybe there should be a sticky about errors Jason since the latest versions of PHP have error reporting high as default and lots of people seem to be worried about the notices they're getting.
Mac
Posted: Fri Jun 28, 2002 8:09 am
by jason
Ahh! I didn't know that. =) I don't have the newest version yet, I will look into it.
Posted: Fri Jun 28, 2002 8:16 am
by twigletmac
Having just thought about it for a second (and checking my php.ini-dist) I think it's affecting people who use the Windows self-installer to install PHP or use the php.ini-recommended file as their php.ini. php.ini-dist has got error reporting E_ALL & ~E_NOTICE.
Mac
Posted: Sat Jun 29, 2002 12:54 am
by cathari
If it is inside the
Code: Select all
function somehandler(){
global $user;
}
you have to declare it first as a global.
twigletmac : Yup! you are right if they installed their php with the installer all the notices and warnings are set to ON. I think they should install php manually.
Posted: Sat Jun 29, 2002 5:21 am
by hob_goblin
i probably am totally wrong on this...but you might try..
$HTTP_POST_VARS['var'];
Posted: Sat Jun 29, 2002 5:39 am
by twigletmac
you have to declare it first as a global.
Not if it is in the $_POST array - $_POST, $_GET, $_SERVER etc. are all autoglobals.
Good point hob_goblin - what version of PHP are you using jayymz?
Mac