473,569 Members | 2,839 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 #1
32 32987
On Fri, 30 Jul 2004 18:22:43 +0100, Nuno Paquete <nm*@ispgaya.pt >
wrote:
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" )
...


Look at the isset() function.
--
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 #2
On Fri, 30 Jul 2004 18:22:43 +0100, Nuno Paquete wrote:
But this code log errors if there is no parameter passed (this heappens at
the first time the page is loaded).


What errors? I don't see why you would get any. PHP is fairly quiet
about using variables that are not yet set.

--
Jeffrey Silverman
je**********@jh u.edu
** Drop "PANTS" to reply by email
Jul 17 '05 #3
"Gary L. Burnore" wrote:
On Fri, 30 Jul 2004 18:22:43 +0100, Nuno Paquete
<nm*@ispgaya.pt >
wrote:
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" )
...


Look at the isset() function.


Try isset first followed by $_GET... as in
if (isset(....) && $_GET[....] ) do something;

php would not look at the $_GET in the above condition unless the
left-side conditional isset(..) is True. By the way, even if you
don’t use isset, you should get a warning, and not an error.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Check-_G...ict135082.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451195
Jul 17 '05 #4

"steve" <Us************ @dbForumz.com> wrote in message
news:41******** **@news.athenan ews.com...
"Gary L. Burnore" wrote:
> On Fri, 30 Jul 2004 18:22:43 +0100, Nuno Paquete
> <nm*@ispgaya.pt >
> wrote:
>
> >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" )
> > ...

>
> Look at the isset() function.
>
>


Try isset first followed by $_GET... as in
if (isset(....) && $_GET[....] ) do something;

php would not look at the $_GET in the above condition unless the
left-side conditional isset(..) is True. By the way, even if you
don't use isset, you should get a warning, and not an error.


I'm partial to array_key_exist s($needle, $haystack) myself.

Garp
Jul 17 '05 #5
Like this:

if (!empty($_GET['menu'])) {
if ($_GET['menu'] == 'downloads') {
...
} else if ...
}

-- Tino Didriksen / Project JJ
Jul 17 '05 #6
On Fri, 30 Jul 2004 21:07:49 GMT, "Garp" <i_**@home.no w> wrote:
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).

Look at the isset() function.


Try isset first followed by $_GET... as in
if (isset(....) && $_GET[....] ) do something;

php would not look at the $_GET in the above condition unless the
left-side conditional isset(..) is True. By the way, even if you
don't use isset, you should get a warning, and not an error.


I'm partial to array_key_exist s($needle, $haystack) myself.


Whilst it seems a bit "naughty" from a purist point of view, I tend to use
@$_GET['x'] - i.e. use error suppression, rather than "isset then use array
key". So:

if (@$_GET['x'] == "something" )
// do something;
else
// either don't do something, or whinge that it's not an expected value

I can't off the top of my head think of any other possible error that it could
mask, other than the notice of use of undefined variable. In this case,
undefined leads to the condition being false, so it doesn't get any further
than that.

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #7
Andy Hassall wrote:
Whilst it seems a bit "naughty" from a purist point of view, I tend to
use
@$_GET['x'] - i.e. use error suppression, rather than "isset then use
array key". So:

if (@$_GET['x'] == "something" )
// do something;
else
// either don't do something, or whinge that it's not an expected value

I can't off the top of my head think of any other possible error that it
could
mask, other than the notice of use of undefined variable. In this case,
undefined leads to the condition being false, so it doesn't get any
further than that.


If you try these
if(@$_GET['x'] == 0)
if(@$_GET['x'] == false)
then they will evaluate to true, even though x key is undefined. You can try
with === but then you lose the flexibility of type conversion.
Jul 17 '05 #8
On Fri, 30 Jul 2004 22:10:51 GMT, Zurab Davitiani <ag*@mindless.c om> wrote:
Andy Hassall wrote:
Whilst it seems a bit "naughty" from a purist point of view, I tend to
use
@$_GET['x'] - i.e. use error suppression, rather than "isset then use
array key". So:

if (@$_GET['x'] == "something" )
// do something;
else
// either don't do something, or whinge that it's not an expected value

I can't off the top of my head think of any other possible error that it
could
mask, other than the notice of use of undefined variable. In this case,
undefined leads to the condition being false, so it doesn't get any
further than that.


If you try these
if(@$_GET['x'] == 0)
if(@$_GET['x'] == false)
then they will evaluate to true, even though x key is undefined.


Yes, fair point, this falls over when expecting values that implicitly convert
to false. It's OK for doing switches e.g. on an 'action' value if you're only
expecting non-false values such as 'add', 'edit', etc., but it's dangerous
laziness if numeric values are coming in. Ah well, I knew it was bad really :-)

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #9
Andy Hassall wrote:
On Fri, 30 Jul 2004 21:07:49 GMT, "Garp" <i_**@home.no w> wrote:
>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).

Look at the isset() function.

Try isset first followed by $_GET... as in
if (isset(....) && $_GET[....] ) do something;

php would not look at the $_GET in the above condition unless the
left-side conditional isset(..) is True. By the way, even if you
don't use isset, you should get a warning, and not an error.


I'm partial to array_key_exist s($needle, $haystack) myself.


Whilst it seems a bit "naughty" from a purist point of view, I tend to
use
@$_GET['x'] - i.e. use error suppression, rather than "isset then use
array key". So:

if (@$_GET['x'] == "something" )
// do something;
else
// either don't do something, or whinge that it's not an expected value

I can't off the top of my head think of any other possible error that it
could
mask, other than the notice of use of undefined variable. In this case,
undefined leads to the condition being false, so it doesn't get any
further than that.

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


Thank you guys. It's working without errors.
I used "@$_GET ..." but isset() function works perfectly.

Jeffrey, the error that I was getting is:

[Fri Jul 30 20:48:28 2004] [error] PHP Notice: Undefined index: menu in
home/nuno/public_html/header.php on line 124

Best regards,

Nuno Paquete

Jul 17 '05 #10

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

Similar topics

1
45534
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
13875
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
3950
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
4277
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
1263
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...
15
128284
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
10689
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
4633
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
1803
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...
2
14645
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...
0
7922
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. ...
1
7668
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...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
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...
0
5218
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.