Forum Moderators: coopster

Message Too Old, No Replies

Removing Ugly Notices

         

kkonline

5:49 am on Sep 3, 2007 (gmt 0)

10+ Year Member



Notice: Use of undefined constant timeadded - assumed 'timeadded' in d:\easyphp\www\gb\index.php on line 25

Notice: Use of undefined constant message - assumed 'message' in d:\easyphp\www\gb\index.php on line 26

Notice: Use of undefined constant author - assumed 'author' in d:\easyphp\www\gb\index.php on line 28

I get the ugly notices when testing on localhost. how to remove them?

If i write

error_reporting(E_ALL ^ E_NOTICE);

the notices are not displayed.

But as you suggested how to declare them in the beginning.
Refer to the code below?

<?php
define('IN_DHG', true);
if(file_exists("install.php")) {
die("Please remove install.php for safety reasons before using this guestbook. Come on, it's better to be safe than sorry.");
}

include("config.php");

$tmp = new template("tmp_header.tpl");
$tmp->replace_tags(array("GUESTBOOK_TITLE" => $gbtitle));
$tmp->output();

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbtable, $conn) or die(mysql_error());

if($newestfirst == "yes") { $ord = "DESC"; } else { $ord = "ASC"; }
$sql = "SELECT * FROM dh_gbentries WHERE trusted = 1 ORDER BY id $ord";
$result = mysql_query($sql, $conn) or die(mysql_error());
if(mysql_num_rows($result) == "0") {
$tmp = new template("tmp_nomsg.tpl");
$tmp->replace_tags(array("LANG_NO_MSG" => $lang_no_msg));
$tmp->output();
}

//notice because of this part

while($g = mysql_fetch_array($result)) {
$g_timeadded = date("jS F Y H:i", $g[timeadded]);
if($allowhtml == "yes") { $g_message = nl2br($g[message]); } else { $g_message = nl2br(htmlspecialchars($g[message])); }
$tmp = new template("tmp_entry.tpl");
$tmp->replace_tags(array("AUTHOR" => $g[author],"DATE_POSTED" => $g_timeadded,"MESSAGE" => $g_message));
$tmp->output();
}

//notice because of above part

$rnad = rand(100000,999999);
$tmp = new template("tmp_postnew.tpl");
$tmp->replace_tags(array("LANG_POST_NEW" => $lang_post_new,"LANG_YOUR_NAME" => $lang_your_name,"LANG_YOUR_MESSAGE" => $lang_your_message,"LANG_TYPE_NUMBER" => $lang_type_number,"LANG_YOUR_IP" => $lang_your_ip,"LANG_ADD_MESSAGE" => $lang_add_message,"IP_ADDR" => $_SERVER['REMOTE_ADDR'],"SECURE_NUMBER" => "$rnad"));
$tmp->output();
?>

Habtom

8:23 am on Sep 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$g_timeadded = date("jS F Y H:i", $g[timeadded]);

Shouldn't a sinqle quotes solve this:

$g_timeadded = date("jS F Y H:i", $g['timeadded']);

Habtom

londrum

8:01 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



sometimes it's good to have the notices so you know what's wrong. you can write them to a file if you like, rather than having them appear on the page.

this is what i stick on all of my pages

<?php
ini_set('error_reporting',E_ALL);
ini_set('display_errors','Off');
ini_set('log_errors','On');
ini_set('error_log','errorlog.txt');
?>

eelixduppy

8:18 pm on Sep 6, 2007 (gmt 0)



>>>this is what i stick on all of my pages

This should really be done in your php.ini file.