error obtaining parameter value from GET URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

error obtaining parameter value from GET URL

Post 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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post 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);
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Try

Code: Select all

if (isset($_GET['xxx'])) {
  $value = $_GET['xxx'];
}
http://www.php.net/manual/en/language.t ... rray.donts
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Indeed, quotes are a must.


Single or double.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply