/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with notice error

I get the following PHP notices/errors and none of the “fixes” I’ve found while searching and googling seem to work:

[CODE]Notice: Undefined variable: display in C:wwwREMOVED.comfolderfile.php on line 44[/CODE]
[CODE]Notice: Undefined variable: uncached_container in C:wwwREMOVED.comfolderfile.php on line 44[/CODE]

Here is the code snippet in question:

[code=php]
if ((PAGE_CACHE_ENABLE > 1) && !$kill_cache && !isset($_REQUEST[‘template_display’]) && !isset($_REQUEST[‘action’]) && !isset($_REQUEST[‘search_options’]) && !preg_match(‘/?print$/’, $_SERVER[‘REQUEST_URI’])){
$res = mysql_query(‘SELECT * FROM ‘ . PAGE_DB_PREFIX . ‘CacheData WHERE url = ” . md5(CACHE_URL) . ”’);
while ($row = mysql_fetch_assoc($res)){
if ($row[‘body’]){
echo ‘<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>’ . “n”;
//echo ‘Cached’;
$display = $row[‘body’];
//<!–NoCache container/login.tpl–>
if (PAGE_CACHE_ENABLE == 2){
preg_match_all(‘/<!–NoCache ([a-zA-Z0-9_/.]+)–>/’, $display, $arr);
$uncached_container = array_unique($arr[1]);

}
if (empty($uncached_container)){
$display = str_replace(‘$generation_time$’, ‘0s’, $row[‘body’]);
echo $display;
exit;
}
}
}
}
$result = array($display, $uncached_container);
return $result;
}
[/code]

I know I can add the following to the file, but that feels like a band-aid instead of a real fix:

[code=php]error_reporting(E_ALL ^ E_NOTICE);[/code]

I’m sure the proper fix is as easy as 1,2,3… but it eludes me.

Anyone have any ideas?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — Which line is line 44?

If it is

$result = array($display, $uncached_container);
[/quote]

You'll want to check that those variable are set before using them. If no results are returned from your sql query they will not be set. Or you can set them to blank values before entering the while loop so they are set but empty.
Copy linkTweet thisAlerts:
@jeffsheadauthorAug 19.2009 — Which line is line 44?

If it is

You'll want to check that those variable are set before using them. If no results are returned from your sql query they will not be set. Or you can set them to blank values before entering the while loop so they are set but empty.[/QUOTE]

Thanks! Yes, it is that line. Sorry I did not point that out.

I'm very new to PHP. Can you give an example?
Copy linkTweet thisAlerts:
@jeffsheadauthorAug 19.2009 — Is this the proper way:

Change from:
[code=php]$result = array($display, $uncached_container);
return $result;[/code]


To:
[code=php]if (isset($result)) {
$result = array($display, $uncached_container);
return $result;
}[/code]
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — You can either set the variables at the begining of your function such as:
[code=php]
$display = '';
$uncached_container = '';
[/code]


Or you can check that they exist before using them such as:
[code=php]
$result = false;
if(isset($display) && isset($uncached_container)){
$result = array($display, $uncached_container);
}
return $result;
[/code]
Copy linkTweet thisAlerts:
@jeffsheadauthorAug 19.2009 — @criterion9

Thanks for your examples. I was not able to "put the pieces together" without them.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — No Problem-o! Glad to help.
×

Success!

Help @jeffshead spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...