Page 1 of 1

error obtaining parameter value from GET URL

Posted: Mon Mar 29, 2004 3:33 pm
by davidklonski
Hi

I have a PHP code which retrieves the value of a GET parameter using the following code (xxx is the variable name):

Code: Select all

if (isset($_GET[xxx])) {
  $value = $_GET[xxx];
}
this code works perfectly when I run it on my machine (I am using Apache Web server), but the same line produces an error when I run it on Xitami Web server.

This is the error:
"Notice: Use of undefined constant xxx - assumed 'xxx' in
> C:\xitami-25\app\webpages\file.inc.php on line 186"

Is my code correct?
Is it a configuration error in the Xitami installation?

thanks in advance

Posted: Mon Mar 29, 2004 3:39 pm
by lostboy
Its a notice that the server doesn't recognize the variable xxx, it should not cause the script to fail. It got this recently when I initialized all my variables to empty strings or 0 fo numerical variables...

I simly turned off error handling(only allowing fatal errors to kill the script) when the script was complete. Notices and Warning are no longer displayed. Place the below at the top of the script...

Code: Select all

// redefine the user error constants - PHP 4 only
define("FATAL", E_USER_ERROR);
define("ERROR", E_USER_WARNING);
define("WARNING", E_USER_NOTICE);

// set the error reporting level for this script
error_reporting(FATAL);

Posted: Mon Mar 29, 2004 5:54 pm
by Steveo31
Try

Code: Select all

if (isset($_GET['xxx'])) {
  $value = $_GET['xxx'];
}
http://www.php.net/manual/en/language.t ... rray.donts

Posted: Mon Mar 29, 2004 6:59 pm
by m3mn0n
Indeed, quotes are a must.


Single or double.

Posted: Tue Mar 30, 2004 1:32 am
by twigletmac
lostboy wrote:Its a notice that the server doesn't recognize the variable xxx, it should not cause the script to fail. It got this recently when I initialized all my variables to empty strings or 0 fo numerical variables...

I simly turned off error handling(only allowing fatal errors to kill the script) when the script was complete. Notices and Warning are no longer displayed. Place the below at the top of the script...

Code: Select all

// redefine the user error constants - PHP 4 only
define("FATAL", E_USER_ERROR);
define("ERROR", E_USER_WARNING);
define("WARNING", E_USER_NOTICE);

// set the error reporting level for this script
error_reporting(FATAL);
Please read the Posting Guidelines (linked from my sig and Sami's) turning down error reporting is NOT a solution it just hides the errors instead of fixing them - when you're developing error reporting should always be at E_ALL.

As Steveo31 pointed out, there is a much better solution to this, using quotes around array elements.

Mac