PDA

View Full Version : global variables and pass by reference again...


dennisb
08-22-2002, 09:15 PM
Working on my local drive with allow_call_time_pass_reference set to Off and register_globals set to Off (the apparent way of the future),
is there any way to use a self-submitting form without getting Undefined index errors when the page first loads? After submitting the form the errors are gone because the index is defined, but when the page first loads I get the error. Thanks in advance - Dennis

Here is the PHP block to receive two variables from an HTML form:

$multiply1 = $_REQUEST['multiply1'];
$multiply2 = $_REQUEST['multiply2'];

function do_multiply($multiply1=0, $multiply2=0){
$multi_answer = ($multiply1 * $multiply2);
if($multi_answer != 0) {
echo ($multi_answer);
}
}

do_multiply($multiply1, $multiply2);

gatorline
08-24-2002, 09:04 PM
To get PHP to stop B&M'ing about undefined indecies and undefined variables... just place an @ symbol before the variable that is haveing the trouble...

------------
$multiply1 = @$_REQUEST['multiply1'];
$multiply2 = @$_REQUEST['multiply2'];

function do_multiply($multiply1=0, $multiply2=0){
$multi_answer = ($multiply1 * $multiply2);
if($multi_answer != 0) {
echo ($multi_answer);
}
}

That should do it..

Regartds,
Todd

dennisb
08-25-2002, 04:45 PM
Thanks. That will do it. Good idea!

Dennis