473,770 Members | 7,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

session_start() ;
if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')
echo "hello";

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

However, this works:

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

Thanks.
Jul 17 '05 #1
6 2054
NotGiven wrote:
session_start() ;
if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_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_SE SSION_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
On Thu, 8 Jul 2004 20:39:39 -0400, "NotGiven" <no****@nonegiv en.net>
wrote:
session_start( );
if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_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_SE SSION_VARS[un']))
echo "hello";

Thanks.


--
gburnore@databa six 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
NotGiven wrote:
if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_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
NotGiven wrote:
session_start() ;
if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')
echo "hello";

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

However, this works:

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

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

you're welcome...

Michael Austin.
Jul 17 '05 #5
*** NotGiven wrote/escribió (Thu, 8 Jul 2004 20:39:39 -0400):
However, this works:

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


It doesn't:

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

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

"Michael Austin" <ma*****@firstd basource.com> wrote in message
news:V2******** *********@newss vr23.news.prodi gy.com...
NotGiven wrote:
session_start() ;
if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')
echo "hello";

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

However, this works:

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


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

if (isset($HTTP_SE SSION_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2709
by: Bill Priess | last post by:
Hey gang, Ok, I'm stumped on this one... I am using the using statement to wrap a SqlDataAdapter that I am using to fill a DataTable. Now, what I need to know is, just how much block-scope applies to objects created in the using scope. For example: <code> static DataTable getTable()
1
315
by: Kepler | last post by:
I have a situation where I need to use a Using statement that creates some records in a database. After that completes, if it completes, I need to do some file creation. Any code I'm putting after the Using statement gives a compiler warning of "Unreachable Code Detected", and it never runs. Why is this happening? I really don't want to put the file manipulation code in the using statement because it's a transaction. I also need for...
3
1934
by: SD WinGirl | last post by:
I am writing an automation utility with the DTE model in C#. I need to open up a C# file and read all the "using statements" contained in that file. I do not see a way to be able to do this with the ProjectItem. Have I missed something? Can someone please suggest a way to accomplish this? Thanks.
8
3706
by: J-T | last post by:
I have a class like below I have a couple of questions about that: 1) I like to use "Using statement" when creating an object of this class,so I had to implement IDisposable.Am I doing this right here? 2) Do I have to be worried about those objects I have created in GetPackageNames() ?? for instance making them null afterward or something? 3) This class is in my business layer As you can see I'm using Microsoft.SQLServer.DTSPkg80...
1
3511
by: pascal_pare | last post by:
Hi, Is there a way to declare a using statement with the CodeDom? Something like: using (obj = new Object()) { obj.DoSomething; }
18
2370
by: Trevor | last post by:
I have seen the "using" statement used in strange ways in some C# code. Example: using (StreamReader sr = new StreamReader("TestFile.txt")) { // do some stuff... } What effect does the using statement give you in this example?
6
1959
by: Juan Zamudio | last post by:
Hi all, I'm using vs 2003, i have a question about using and as, i was reading in programing .net components that one way to avoid null references inside using was using as, something like this: using(var as IDisposable){ ..... } the book saids that if the conversion is null the code inside using will not run, but i cant make it work, I have a FileStream that opens a file, the path is a parameter, something like this:
5
7143
by: Hillbilly | last post by:
MSDN Remarks "as a rule" the using statement should be used when instantiating objects which inherit IDisposable. Other than the obvious unmanaged objects like the file system example, fonts and the database how else may it be determined which classes and their objects inherit IDisposable? And the remarks imply the using statement is a different and perhaps more efficient way to use objects than try-catch-finally? ...
3
1686
by: CSharper | last post by:
I have a using statement something like the following try { using(SqlConnection cnn = ...) { } catch(Exception e1) { }
2
1321
by: mcfly1204 | last post by:
What is the best practice for returning values from within a using statement? For instance: using (SqlConnection Conn = new SqlConnection(strConn)) { SqlCommand cmd = new SqlCommand("spWhatever", Conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@parm1", SqlDbType.VarChar, 128); cmd.Parameters.Value = strOne; ...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.