Author Topic: [SOLVED] undefined index error when updating to php 5  (Read 754 times)

0 Members and 1 Guest are viewing this topic.

Offline stevenreidTopic starter

  • Irregular
    • View Profile
[SOLVED] undefined index error when updating to php 5
« on: October 03, 2008, 08:48:23 AM »
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.



Online aebstract

  • Devotee
    • View Profile
Re: undefined index error when updating to php 5
« Reply #1 on: October 03, 2008, 09:06:20 AM »
You said you had a lot of errors? What errors are you getting? Can you post them?
There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.

Online PFMaBiSmAd

  • PHPFreaks Recommended
  • Freak!
  • *
    • View Profile
Re: undefined index error when updating to php 5
« Reply #2 on: October 03, 2008, 09:20:04 AM »
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.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline stevenreidTopic starter

  • Irregular
    • View Profile
Re: undefined index error when updating to php 5
« Reply #3 on: October 03, 2008, 09:39:25 AM »
fantastic - another little bit of PHP I've learned about, cheers.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.