Page 1 of 1

Removing Ugly Notices

Posted: Mon Sep 03, 2007 12:50 am
by kkonline
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?

Code: Select all

<?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();
?>

Posted: Mon Sep 03, 2007 1:09 am
by s.dot
Yes. Your array indexes are not constants. They are strings. Treat them as such.

Code: Select all

$g[timeadded]);
should be

Code: Select all

$g['timeadded']);
Along with the other $g[] references.

Posted: Mon Sep 03, 2007 1:17 am
by kkonline
scottayy wrote:Yes. Your array indexes are not constants. They are strings. Treat them as such.

Code: Select all

$g[timeadded]);
should be

Code: Select all

$g['timeadded']);
Along with the other $g[] references.

Scottyy after replacing by $g['timeadded'] i still get the same notices.
So i want to know how do i define the variables in the beginning of the script.

I know i can use

Code: Select all

//error_reporting(E_ALL ^ E_NOTICE);
but i want to solve the problem not hide it!

Posted: Mon Sep 03, 2007 1:18 am
by s.dot
You need to replace $g[message] and $g[author] and anything that's $g[something] to $g['something'].