Removing Ugly Notices

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Removing Ugly Notices

Post 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();
?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You need to replace $g[message] and $g[author] and anything that's $g[something] to $g['something'].
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply