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

$_REQUEST problem

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
"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

P: n/a
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

P: n/a
>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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
.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 discussion thread is closed

Replies have been disabled for this discussion.