By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

why doesn't this work? - using && with an IF statement

P: n/a
session_start();
if (isset($HTTP_SESSION_VARS[un']))&&($HTTP_SESSION_VARS['un'] != '')
echo "hello";

It doesn't throw an error it just doesn't display anything

However, this works:

session_start();
if (isset($HTTP_SESSION_VARS[un']))
echo "hello";

Thanks.
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
NotGiven wrote:
session_start();
if (isset($HTTP_SESSION_VARS[un']))&&($HTTP_SESSION_VARS['un'] != '') echo "hello"; (-----(=======================))
The &&'s are outside the if () !!!
It doesn't throw an error it just doesn't display anything
I think you should have received a "parse error"
However, this works:
PHP can be nice sometimes, can't it? :)
session_start();
if (isset($HTTP_SESSION_VARS[un'])) ______________________________^^^^^
I assume this is a typing mistake
echo "hello";

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #2

P: n/a
On Thu, 8 Jul 2004 20:39:39 -0400, "NotGiven" <no****@nonegiven.net>
wrote:
session_start();
if (isset($HTTP_SESSION_VARS[un']))&&($HTTP_SESSION_VARS['un'] != '')
Could it be that you missed the single quote before un' that you
missed here?

echo "hello";

It doesn't throw an error it just doesn't display anything

However, this works:

session_start();
if (isset($HTTP_SESSION_VARS[un']))
echo "hello";

Thanks.


--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #3

P: n/a
NotGiven wrote:
if (isset($HTTP_SESSION_VARS[un']))&&($HTTP_SESSION_VARS['un'] != '')


Watch your parentheses and a missing single quote.

On a side note, unless you are writing this for older versions of PHP, you
should use $_SESSION array instead.
Jul 17 '05 #4

P: n/a
NotGiven wrote:
session_start();
if (isset($HTTP_SESSION_VARS[un']))&&($HTTP_SESSION_VARS['un'] != '')
echo "hello";

It doesn't throw an error it just doesn't display anything

However, this works:

session_start();
if (isset($HTTP_SESSION_VARS[un']))
echo "hello";
because the echo statment is not a part of the if statement. you need

if (isset($HTTP_SESSION_VARS['un'])) {
echo "hello";
}
Thanks.

you're welcome...

Michael Austin.
Jul 17 '05 #5

P: n/a
*** NotGiven wrote/escribi (Thu, 8 Jul 2004 20:39:39 -0400):
However, this works:

session_start();
if (isset($HTTP_SESSION_VARS[un']))
echo "hello";


It doesn't:

Parse error: parse error, expecting `']''

--
--
-- lvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #6

P: n/a

"Michael Austin" <ma*****@firstdbasource.com> wrote in message
news:V2*****************@newssvr23.news.prodigy.co m...
NotGiven wrote:
session_start();
if (isset($HTTP_SESSION_VARS[un']))&&($HTTP_SESSION_VARS['un'] != '')
echo "hello";

It doesn't throw an error it just doesn't display anything

However, this works:

session_start();
if (isset($HTTP_SESSION_VARS[un']))
echo "hello";


because the echo statment is not a part of the if statement. you need

if (isset($HTTP_SESSION_VARS['un'])) {
echo "hello";
}

That's not true. You only need these parenthesis when wanting to execute
more than one line.
in this case, where only the echo is done, he don't need those
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.