Forum Moderators: coopster

Message Too Old, No Replies

Undefined Variable/Constant misery with v4.4.2

Maybe a configuration problem?

         

neophyte

12:45 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



Hello All -

I developed and deployed a site about a year ago using php 4.4.1 (I think). All tested well and ran perfectly both locally as well as live.

Now, this client wants me to do some maintenance on a few of his pages, but when I started previewing pages (locally) that I haven't even touched yet, I'm getting error notices all over the place like:

"Notice: Undefined variable: name in c:\apache\htdocs\danielik\guest\guestbook_sign.php on line 108", and:

"Notice: Use of undefined constant NAME_ERROR - assumed 'NAME_ERROR' in c:\apache\htdocs\danielik\guest\validate_guest.php on line 10"

Wow, what happened?

The only thing that changed is that I got a new hard drive and reinstalled a new(er) version of php (4.4.2) as well as apache.

I've googled the problem with a lot of hits but nothing that works for me to remedy this issue - I've turned on register_globals (which I didn't want to do) but still the same errors - so I turned it back off and tried again with same aggravating result.

On the live site (no maintenance has been uploaded yet) it still works perfectly so I'm at a real loss.

Is it some php configuration issue that I haven't dealt with?

All guidance HUGELY appreciated.

Neophyte

coopster

2:42 pm on Feb 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes. It is the level of error_reporting in the php.ini configuration directives.
It is good to have the error reporting levels cranked up on a development box so you write cleaner code, but definitely turn it off on a production server. Or I should say use the error_log instead anyway. DO NOT send the error messages to the browser on a LIVE box.

vevs

2:58 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



yes, coopster is right. In case you do not want to mess up with php.ini file you can add
error_reporting(0);
at the top of your PHP files

neophyte

11:20 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



Coopster and vevs -

Appreciate the insight, but this either means that I had error reporting turned off on my previous install of php or something else wierd is going on.

My aim is to write code that is as error free as possible so - while I'm happy to be alerted to the error(s), I'm losing sleep over how to fix it.

Here's one code snippet (which is at the very top of the page) that's causing one of the "undefined variable" errors:

<?php

require_once '../_include/db.query.inc.php';

foreach($_POST as $key => $value){
$arr = explode("_", $key);
$buttonHit=$arr[0];
$rowId=$arr[1];
}

if ($buttonHit == 'Edit') {

$query="SELECT id, name, email
FROM email
WHERE id = $rowId";

$result = dbQuery($query, TRUE);

$viewRows = mysql_fetch_assoc($result['recs']);

$rowId=$viewRows['id'];
$name=$viewRows['name'];
$email=$viewRows['email'];

include ('rates.edit.php');
exit();
}
?>

The error throws at the line "if ($buttonHit == 'Edit')", and names $buttonHit as the undefined variable.

Any clues as to the error of my ways? Does one now (or atleast since v4.4.1) have to declare/define variables?

Neophyte

Dijkgraaf

11:39 pm on Feb 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$buttonHit is in the foreach loop, so if there aren't any $_POST values it would not get set.

Try setting $buttonHit="" before the loop.

neophyte

11:52 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



Dijkgraaf -

That was it! Cool. Thanks so much!

No more error messages which means now I can get some sleep.

Neophyte