Page 1 of 1

whats the mistake??

Posted: Mon Sep 24, 2007 2:54 pm
by claws

Code: Select all

if(isset($_SESSION['UserType']) && $_SESSION['UserType']=="Administrator" || $_SESSION['UserName']==$reply_arr['user_name'])
{

...
...

}
if a person is logged in all the session variables will be set otherwise not.

so if person is not logged in. the above code should not show any mistake because
isset($_SESSION['UserType']) will return false.

and therefore further checking is not done.
but to my surprise it shows the following error:
Notice: Undefined index: UserName in D:\htdocs\temp.php on line 144

one more...

Posted: Mon Sep 24, 2007 3:07 pm
by claws

Code: Select all

echo "xyz".  isset($_SESSION['UserName'])?$_SESSION['UserName']:'Guest'. "xyz"
should workfine if a person is not logged in ( session variables are not set) but it shows the error

Notice: Undefined index: UserName in D:\htdocs\temp.php on line 79

Posted: Mon Sep 24, 2007 8:22 pm
by feyd
The last snippet appears fine, technically.

Posted: Tue Sep 25, 2007 12:21 am
by Hemlata
Hello claws

You should slightly modify your code to use braces while using compulsory conditions. Your previous code was checking condition as whether $_SESSION['UserType'] is set or not AND $_SESSION['UserType'] is administrator OR $_SESSION['UserName'] is $reply_arr['user_name']. Means conditions within if block was AND and OR, so it was executing the if block. Modify your code with following code and i think you could get the required results..

Code: Select all

if(isset($_SESSION['UserType']) && ($_SESSION['UserType']=="Administrator" || $_SESSION['UserName']==$reply_arr['user_name']))
Regards,