undefine index?????

zyreena

New Member
Messages
57
Reaction score
0
Points
0
PHP:
if($_GET['view'] == 'login' or !isset($_GET['view']))

wat wil i do so dat this condition will work. it gives me an error: undefined index: view
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
You need to actually reverse your statement. When PHP encounters what you have programmed now and $_GET['view'] is not set, it gives you the error.

Code:
if(!isset($_GET['view']) || $_GET['view'] == 'login')
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
When you do something like if (condition 1 or condition 2 or condition 3...) the conditions are evaluated in order from left to right. So, if there's an error in condition 1, it will never reach condition 2 or 3. Since $_GET['view'] is not set, your condition 1 has an error - you are trying to operate on something that doesn't exist.
 

ichwar

Community Advocate
Community Support
Messages
1,454
Reaction score
7
Points
0
When you do something like if (condition 1 or condition 2 or condition 3...) the conditions are evaluated in order from left to right. So, if there's an error in condition 1, it will never reach condition 2 or 3. Since $_GET['view'] is not set, your condition 1 has an error - you are trying to operate on something that doesn't exist.
good catch garrett. The other thing to note with that chance zyreena is that in php there is no "or" you need to use the command "||" ;)
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
good catch garrett. The other thing to note with that chance zyreena is that in php there is no "or" you need to use the command "||" ;)

I actually think they added "and" and "or" in one of the recent PHP versions, but I could be wrong. I prefer the symbol syntax because I've used a lot of other C type languages and I'm stuck in my ways :p
Edit:
http://www.php.net/manual/en/language.operators.logical.php

I would still stick to the || operator because "or" operates differently.
 
Last edited:

zyreena

New Member
Messages
57
Reaction score
0
Points
0
hmmm. but i've read you can use 'or' and 'and' in the latest version. tnx guys for mor info
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Feel free to use 'and' and 'or' forms when necessary if you understand operator precedence and can add explicit parentheses to:
Code:
$foo='a' or false ? 'b' : 'c' and 'd';
$bar='a' || false ? 'b' : 'c' && 'd';
so the parenthesized versions are parsed equivalently.

In general, you'll use '&&' and '||' much more than 'and' and 'or'. If you don't understand precedence, you should study it before going much further.
 
Top