Notice: Undefined index:

[php] echo '$portal_view: ’ . $portal_view;
if(isset($portal_view)){$invite = $_SESSION[‘portal_view’];}else{$invite=null;$portal_view="*";}[/php]

the echo statement (inserted for testing) outputs *, which is what $portal_view is suppose to be defined as (a string)

Why I am getting an undefined index warning message on this variable?

You’re using it before you are defining it. If you did something like below, you won’t get that error, because it’s being defined before you’re using it.

[php]$portal_view = '’;
echo '$portal_view: ’ . $portal_view;
if(isset($portal_view)){$invite = $_SESSION[‘portal_view’];}else{$invite=null;$portal_view="
";}[/php]

How am I using it before it is defined when it contains a string of “*”? Is not containing a string, defined?
This is the line of code that is suppose to set the variable, and it works too, I just get this warning… The isset() statement is not solving the problem…

Also, the echo statement (inserted for testing, verifies that there is something in the variable)

And just to make sure (for testing), I inserted
[php]$portal_view = ‘*’;[/php]
right before the line that causes the error and still get an undefined index warning.

Appreciate the reply, but it didn’t help…

Can anyone tell me what would cause an undefined index warning on a variable that IS defined? (It contains a string.)

BTW:Using the isset() statement has always worked in the past for me. This time it’s not working…
Expected Solution (Not working): [i]

Assuming I am unable to find the reason for this, thus not be able to fix it. My workaround will be to add the following line at the top of my set_variables.php file.
[php]error_reporting(E_ALL ^ E_NOTICE);[/php]
Which seems to disable error reporting from within the code.

And I think adding this to the end of the file should turn it back on.
[php]error_reporting(E_ALL);[/php]?

Sorry, I mis-read your initial post and I thought the error happened on your “echo” testing line.

Anyway, your code runs fine on my server without issue, if i define

[php] $portal_view = ‘*’; [/php]

Obviously, you have that defined elsewhere that you didn’t display.

I don’t get any errors at all, so I don’t think you have a coding issue with that section of code.

Create a new PHP file with only this in it…

[php]<?php
$portal_view = ‘’;
echo '$portal_view: ’ . $portal_view;
if(isset($portal_view)){$invite = '
’;}else{$invite=null;$portal_view="*";}
?>[/php]

Do you get the error? that’s what I’m testing with.

You can post a link, but it has to be as text until I think 10 posts…

Great suggestions! Thanks. I put the code in it’s own file and it works fine.

[php]if(isset($portal_view)){$invite = '’;}else{$invite=null;$portal_view="";}[/php]

Also works just fine on it’s own even if the variable is not set.

You have helped me determine that the line of code reporting an error works just fine on it’s own.

…So I need to look deeper into the code…

Thanks for helping getting to the next step, I know where to look now. I’ll post again later with update.

I fixed it! I think…

Seems to be the problem was I was pulling from $_GET before checking $_SESSION for my variable. My code is designed to use $_SESSION, and has an include to pull from $_GET to set $_SESSION variables.

Thanks for helping me tracking this down.

Sponsor our Newsletter | Privacy Policy | Terms of Service