Jump to content

[SOLVED] undefined index error when updating to php 5


stevenreid

Recommended Posts

i've used the following code in the past

 

if ($_REQUEST["newsstory"] != ""){

$row = $_REQUEST["newsstory"];

}else{

$row = $lastNews;

}

 

The server the site was on has been updated to version 5.1.6 from 4.3.9 and now I get a whole lot of errors.

 

newsstory is a querystring, previously it was just a case of - if the querystring is blank, use this variable instead (which is defined earlier on). So I'm wondering if there's a way to fix this. I'm really not knowledgeable in PHP, so sorry if the fix seems like it's something obvious.

 

at the moment I'm using error_reporting(0); and everything works fine on the surface, but of course I'd like to know how to have it work properly.

 

Cheers.

 

 

 

Those errors were always present in your code but the error_reporting or display_errors setting was causing them to be hidden.

 

The reason for the error in the code you posted is because the code is referencing the value of a variable when that variable does not exist. The correct way to perform that logic is to use the isset() function. The isset() function checks if the variable exists without referencing its' value and no error is generated when the variable does not exist.

 

On a live server, the display_errors setting should be OFF and on a development system it should be ON. error_reporting should always be set to at least E_ALL so that actual errors that occur are logged and you have a record of problems, like a hacker feeding your script unexpected and invalid data that triggers errors in an attempt to break into your script.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.