473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

$_REQUEST problem

This line of code make an "Undefined index" error on my PC, however it is
okay on my friend's PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];

Jul 17 '05 #1
7 12206
"melty" <m@lty.com> wrote in message news:1090294263.937002@hkpu01...
This line of code make an "Undefined index" error on my PC, however it is
okay on my friend's PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];


Try accessing the page with a query string of "?name=foo" or sending a
$_POST variable called "name"...
Jul 17 '05 #2
kingofkolt wrote:
"melty" <m@lty.com> wrote in message news:1090294263.937002@hkpu01...
This line of code make an "Undefined index" error on my PC, however it is
okay on my friend's PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];

Try accessing the page with a query string of "?name=foo" or sending a
$_POST variable called "name"...


A high level of error reporting will also cause PHP to print those
messages/warnings.

In php.ini;

error_reporting = E_ALL & ~E_NOTICE

should suffice.
Jul 17 '05 #3
>This line of code make an "Undefined index" error on my PC, however it is
okay on my friend's PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];


My approach to this is: always use isset() on any variable you
aren't absolutely sure is set before trying to use its value. You
can NEVER be sure that a particular variable in $_GET, $_POST,
$_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
execution of your page. Consider any "undefined index" or "undefined
variable" message to be a bug in your code.

Also, use error_reporting(E_ALL) to make sure that if you use
an uninitialized value, it gets reported.

Gordon L. Burditt
Jul 17 '05 #4
"Gordon Burditt37" wrote:
This line of code make an "Undefined index" error on my PC, however it is
okay on my friend’s PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];


My approach to this is: always use isset() on any variable you
aren’t absolutely sure is set before trying to use its value.
You
can NEVER be sure that a particular variable in $_GET, $_POST,
$_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
execution of your page. Consider any "undefined index" or

"undefined variable" message to be a bug in your code.

Also, use error_reporting(E_ALL) to make sure that if you use
an uninitialized value, it gets reported.

Gordon L. Burditt</font>


I second Gordon’s comment. Tight error reporting ensures that you
catch some very pesky bugs- more work, more reward.

If undefined is a valid value for any variable--in other works you
don’t want to get any warnings, then use this function around your
variable.
$somevar = nullit($_REQUEST["name"]);

Function nullit(&$varin) { //must pass by reference, so there is no
explicit copying of var data
//if undefined variable, then returns ’’ without doing an error,
otherwise just returns the var.
//this is done so we don’t get warning
if (isset($varin)) {
return ($varin);
}
else {
return (’’);
}
}

--
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-_REQUEST...ict131132.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578
Jul 17 '05 #5
"Gordon Burditt37" wrote:
This line of code make an "Undefined index" error on my PC, however it is
okay on my friend’s PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];


My approach to this is: always use isset() on any variable you
aren’t absolutely sure is set before trying to use its value.
You
can NEVER be sure that a particular variable in $_GET, $_POST,
$_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
execution of your page. Consider any "undefined index" or

"undefined variable" message to be a bug in your code.

Also, use error_reporting(E_ALL) to make sure that if you use
an uninitialized value, it gets reported.

Gordon L. Burditt</font>


I second Gordon’s comment. Tight error reporting ensures that you
catch some very pesky bugs- more work, more reward.

If undefined is a valid value for any variable--in other works you
don’t want to get any warnings, then use this function around your
variable.
$somevar = nullit($_REQUEST["name"]);

Function nullit(&$varin) { //must pass by reference, so there is no
explicit copying of var data
//if undefined variable, then returns ’’ without doing an error,
otherwise just returns the var.
//this is done so we don’t get warning
if (isset($varin)) {
return ($varin);
}
else {
return (’’);
}
}

--
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-_REQUEST...ict131132.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578
Jul 17 '05 #6
"Gordon Burditt37" wrote:
This line of code make an "Undefined index" error on my PC, however it is
okay on my friend’s PC.
Anyone has this experience?
$somevar = $_REQUEST["name"];


My approach to this is: always use isset() on any variable you
aren’t absolutely sure is set before trying to use its value.
You
can NEVER be sure that a particular variable in $_GET, $_POST,
$_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
execution of your page. Consider any "undefined index" or

"undefined variable" message to be a bug in your code.

Also, use error_reporting(E_ALL) to make sure that if you use
an uninitialized value, it gets reported.

Gordon L. Burditt</font>


I second Gordon’s comment. Tight error reporting ensures that you
catch some very pesky bugs- more work, more reward.

If undefined is a valid value for any variable--in other works you
don’t want to get any warnings, then use this function around your
variable.
$somevar = nullit($_REQUEST["name"]);

Function nullit(&$varin) { //must pass by reference, so there is no
explicit copying of var data
//if undefined variable, then returns ’’ without doing an error,
otherwise just returns the var.
//this is done so we don’t get warning
if (isset($varin)) {
return ($varin);
}
else {
return (’’);
}
}

--
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-_REQUEST...ict131132.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578
Jul 17 '05 #7
.oO(John Unleaded Smith)
A high level of error reporting will also cause PHP to print those
messages/warnings.

In php.ini;

error_reporting = E_ALL & ~E_NOTICE

should suffice.


Not on a development system. Better fix the problem instead of turning
off notices.

$somevar = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';

Even if it's "only" a notice, it's possible that the code does not
exactly do what you expect it to do. Fixing notices prevents some hard
to find bugs.

Micha
Jul 17 '05 #8

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

Similar topics

1
by: toufik toufik | last post by:
Hi, I've a variable that can come with the GET and POST method, So I use $_REQUEST to get it When I use a simple href href="myFile.php?myVar=value" I have myVAr in the $GET and $_REQUEST arrays....
0
by: Sandro Dentella | last post by:
I have some scripts that used to work under webmin under Debian(woody). Under Debian Sarge php passed from 4.1.2 to 4.3.4 and I'm experimenting several problems. Among the others, array...
2
by: Sean | last post by:
Hello, The isset($_REQUEST) works okay on other servers but not on mine. The way the application works is the links are provided as: http://url.com/cc.php?page=currencies&new And then in...
4
by: Geoff Soper | last post by:
I'm working on an authentication system in which it's possible that a user might be requested to log-in as a result of submitting a form if the inactivity timeout is exceeded. In order that they...
2
by: Geoff Winkless | last post by:
Hi My knowledge of php is regrettably poor but I need to call a third-party php script from within a bash cgi script (don't ask why, it's a long story). Now normally (with eg perl-cgi) to do...
11
by: jmark | last post by:
I have seen some code like $value = strval($REQUEST); I would like to know what is the use of strval here since $_REQUEST values are strings?
4
by: Fred!head | last post by:
Hi, Probably this is a newbie question so I appreciate you bearing with me. I've got an application where users can create forms with name= values they define. I'd like to write a script that...
6
by: sathyashrayan | last post by:
Dear Group, Please look at the following demo link. http://www.itsravi.com/demo/new_pms/admin/addproject.php
3
by: hassnajib | last post by:
I am having problem retrieving $_REQUEST array key/value i submintted using post method. here is the simple form I am posting: <html> <head> </head> <body> <form...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
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,...

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.