473,698 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if $_GET["menu"] is null.

Hi group.
I'm using this code to see if is there any parameter for variable "menu":

if($_GET["menu"] == "downloads" )
....

But this code log errors if there is no parameter passed (this heappens at
the first time the page is loaded).

I tryed this code:

if($_GET["menu"] != ""){
if($_GET["menu"] == "downloads" )
...

But this log the same error on the second line.
Any help hould be greattly appreciated.
Thanks in advance,

Nuno Paquete
Jul 17 '05
32 33029
Zurab Davitiani wrote:
Because once you determine that $_GET['option'] is *defined* then both of
these:

$_GET['option'] == '0'
$_GET['option'] == 0

will do exactly the same.


I'm replying to myself here, but I believe I made a mistake. These 2 are not
exactly the same since you'd still need to do an empty check in the second
case. Or strcomp.

Anyway, if you don't need to know about whether a GET variable is defined or
not, you don't need to use ==, you can just use strcomp. I think that's
what Chung Leong said, and I don't really disagree there.
Jul 17 '05 #31
Tim Streater wrote:
If option is undefined, then I would have thought that $_GET['option']
would also be undefined. If its undefined it cannot be equal to zero or
any other value, so why is the else clause not taken?


That's a big part of what this sub-thread was about. Because undefined value
is equal to 0/false/[empty string] with implicit type conversion. If you
need to know whether a variable is defined or not, use isset; and don't
turn off undefined notices to catch them. If it doesn't matter and you are
just comparing string values, use strcomp (or another way of string-only
comparison).
Jul 17 '05 #32
"Zurab Davitiani" <ag*@mindless.c om> wrote in message
news:0n******** ********@newssv r27.news.prodig y.com...
Zurab Davitiani wrote:
Because once you determine that $_GET['option'] is *defined* then both of these:

$_GET['option'] == '0'
$_GET['option'] == 0

will do exactly the same.
I'm replying to myself here, but I believe I made a mistake. These 2 are

not exactly the same since you'd still need to do an empty check in the second
case. Or strcomp.

Anyway, if you don't need to know about whether a GET variable is defined or not, you don't need to use ==, you can just use strcomp. I think that's
what Chung Leong said, and I don't really disagree there.


I made somewhat of an mistake here too. Forgot that *any* non-numeric
string gets converted to 0 on numeric comparison. So the following is true:

if("Bobo the Clown" == 0) {
echo "Bobo is nothing!";
}

But the bottomline is that isset() doesn't help you here.

--
Obey the Clown - http://www.conradish.net/bobo/
Jul 17 '05 #33

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
45636
by: Luis | last post by:
Is there an easier way to check if any of the fields returned in a select statement have null values? After running this command: set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from SomeTable where...") I could check each field this way:
2
13883
by: sam | last post by:
For Example, If I delete two times like the below code, the program will behave differently. is this correct? As C++ FAQ the delete checks where or not f1 has memory. How can the following program can go wrong? class foo{ // }; int main{ foo *f1 = new foo()
2
3956
by: ad | last post by:
I have a string like string sNo. I want to cast it to int with int.Parse(sNo) but if the string is null or empty, it will thow exception. I must check if sNo is not null and is not empty before cast like: if ((sNo<>null) && (sNo<>"")) Have there any function to check the null and "" at once
1
4279
by: MattH | last post by:
I can't seem to figure out the syntax for checking for null values in asp.net. Can anyone point me in the right direction? Also, is there a common area on the MSDN for syntax lookup? Thanks!
1
1267
by: WebBuilder451 | last post by:
Why will this not work? it comes back with an error saying it can't work because the value is null this is a dataset value retreaved from db and it is null. call to check for null Me.txtExtra1.Text = Me.MNS(.usrExtra1) function to return a default value: Public Function MNS(ByVal s As Object) As String If IsDBNull(s) Then Return String.Empty
15
128300
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
3
10692
by: Jim | last post by:
I am trying to use a combo box in order to write a query on the fly. I want to check for a null entry so i can replace it with "Like *" or similar. If Combo0.Value = Null Then MsgBox ("null") this however doesnt seem to work... even when there is no value set the msgbox doesnt appears any help much appreciated...
4
4640
by: Richard Coltrane | last post by:
Hi there, Im stepping into C# from VB.net. In all the examples ive seen about raising events the following construct is used: if (myevent != null) myevent(this,args); Whats the purpose of the test for null? Is that testing to see if the underlying delegate is null? If so when would it be?
1
1811
by: Sparky74 | last post by:
Hi Everybody. I have been searching for many hours for an answer to this problem. I hope somebody can help me. I have a C# .NET client application that connects to a TCP/IP C++ server application that I have maintained for a number of years. What I am finding is that Socket.Close() does not actually sever the client connection from my server application. Actually, my statement above isn't entirely true - Socket.Close() *does* work as...
2
14655
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the following code passes string.Empty as parameter but how to pass null value?), I cannot check for null value...
0
8683
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
8610
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
9170
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
9031
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
8902
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,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
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();...
1
3052
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
2339
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.