Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_REQUEST issues

Status
Not open for further replies.

Firemyst

Programmer
Mar 10, 2003
62
0
0
US
Hi there,

I have multiple PHP 4 scripts which set variables in the program similar to:

$r_admin_email = $_REQUEST["admin_email"];

where $_REQUEST["admin_email"]; is obviously passed in through a form.

However, there are times when this value is not passed along. Then the above assignment gives me the following warning:

Undefined index: admin_email in C:\Inetpub\cgi-bin\update_config.php on line 46

Besides turning off warnings, is there any way around this other than the following code:
if (array_key_exists ("admin_email", $_REQUEST)) {
$r_admin_email = $_REQUEST["admin_email"];
} else {
$r_admin_email = "";
}
???????????

I hate to have to do it the above way, because some of the scripts have over 50 variables that can be passed in.

Thanks!

 
Well, there are some client side options using javascript whereby you can either enforce the need for a value (sort of) or assign a null or blank value if the field is empty. Of course, this only works if the user has javascript turned on.

The one thing that puzzles me about your example is that it sounds like the field itseld (the email textbox) is not present in some cases. Why would that be, that it would throw off the code as you explained above?

Note: all data should be checked for validity, including proper formatting of emails (someone@domain.TLD), names are only alpha, numbers are only etc.



Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
I'm just learning PHP but when ever I write a varible i say something like
Code:
<?php
$r_admin_email = $_REQUEST['admin_email'];
echo(&quot;$var&quot;)
?>
and on yours you had
Code:
$r_admin_email = $_REQUEST&quot;admin_email&quot;;
my point is you didnt have the little brackets...I'm not sure if your allowed to do what you doin or I just havent learned that much but maybe you can try that and see if it helps any.
Jammer1221
 
Hey everyone,

Yes, I do use the backets. I just put up the snippet of PHP code.

As for the javascript option -- it's not possible. We're not allowed to use javascript to check. So everything has to be on the PHP side.

If the PHP developers are reading this, I should just be allowed to do:

$r_admin_email = $_REQUEST&quot;admin_email&quot;;

whether or not there's a value and not have a ga-zillion warnings pop up.

Does anyone else have any ideas?
 
Using an uninitialized variable is an error.
You could just turn off error reporting where you assign your variables, and turn it back on again when you are done.

//Daniel
 
Daniel,

How do I turn the error reporting on and off as you suggested?

Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top