PDA

View Full Version : Netscape Errors


Jeffrey
01-29-2001, 01:14 AM
On my main page ( www.caviesgalore.com ) I get:

Warning: Cannot add header information - headers already sent by (output started at /home2/cavy4me/public_html/index.php:7) in /home2/cavy4me/public_html/forums/global.php on line 1495

Warning: Cannot add header information - headers already sent by (output started at /home2/cavy4me/public_html/index.php:7) in /home2/cavy4me/public_html/forums/global.php on line 1501

When I try to display the last 4 posts. The code I'm using is, what can I do?:

<?
chdir("/home/cavy4me/public_html/forums/");
include("global.php");

$num_active = 4;
$num_chars = 40;

$db=mysql_connect($servername,$dbusername,$dbpassw ord);

mysql_select_db($dbname);


$querylatest="SELECT * FROM thread WHERE forumid='1' OR forumid='2' OR forumid='3' OR forumid='4' OR forumid='5' OR forumid='6' OR forumid='10' ORDER BY lastpost DESC LIMIT $num_active";

$resultlatest = mysql_query($querylatest,$db);

while ($latest_array = mysql_fetch_array($resultlatest)) {

// Get Forum Infomation
$query_forum = "select * from forum where forumid='$latest_array[forumid]'";
$result_forum = mysql_query($query_forum,$db);
$forum_info_array = mysql_fetch_array($result_forum);

// split the date up a bit
$datestr1 = substr($latest_array["dateline"],0,10);
$datetime = substr($latest_array["dateline"],11,8);

$querythread="SELECT * FROM post WHERE threadid='$latest_array[threadid]' ORDER BY dateline ASC LIMIT 1";

$result_thread_text= mysql_query($querythread,$db);

$result_thread_array = mysql_fetch_array($result_thread_text);

$newstitle = $latest_array["title"];
$newsposter = $latest_array["postusername"];
$newsposterid = $result_thread_array["userid"];
$newsdate = date("D j M Y", $latest_array["dateline"]);
$newstext = substr(strip_tags($result_thread_array["pagetext"]),0,$num_chars);
$newsthreadid = $latest_array["threadid"];
$newscomments = $latest_array["replycount"];
$threadforumid = $latest_array["forumid"];
$threadforum = $forum_info_array["title"];
$threadiconid = $latest_array["iconid"];

// split apart long URL strings
$newstext=eregi_replace("\\[url\\]www.([^\\[]*)\\[/url\\]","<a href=\"http://www.\\1\" target=_blank>\\1</a>",$newstext);
$newstext=eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>(hyperlink)</a>",$text);

$newstext=eregi_replace("\\[url=\"([^\"]*)\"\\]([^\\[]*)\\[\\/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$newstext);
$newstext=eregi_replace("\\[url=([^\"]*)\\]([^\\[]*)\\[\\/url\\]","<a href=\"\\1\" target=_blank>(hyperlink)</a>",$newstext);
//special thank-you to Menno at vBulletin Community Forum for coming up with the above part!

if ($threadiconid==0) {
$threadicon = "";
}
else {
$threadicon = "<img src=\"/bbs/images/icons/icon$threadiconid.gif\" alt=\"Thread icon\">&nbsp;";
}

if ($newscomments==1) {
$commenttext = "reply";
}
else {
$commenttext = "replies";
}

print("
<table width=\"90%%\" cellpadding=\"2\" BORDER=0 ALIGN=CENTER>
<tr><td width=\"100%%\" bgcolor=\"#99CCFF\" class=\"sidebar1\">
<FONT SIZE=-1><B>Subject: $newstitle</B></FONT><br>
</td></tr><tr>
<td width=\"100%%\" class=\"sidebar1\" bgcolor=\"#f7f7f7\">
<FONT SIZE=-1>Read the <a href=\"http://www.caviesgalore.com/forums/showthread.php?threadid=$newsthreadid\" class=\"sidebar1\">$newscomments $commenttext</a><br></FONT>
</td></tr></table>
");
}

?>

01-29-2001, 03:43 PM
The most common cause for the error message you have there is the code trying to send an HTTP header after output has already been sent to the browser.

For example:
<?
echo $moo;
setcookie("moocookie", $moo);
?>
will not work, because PHP is trying to send an HTTP header (setcookie) after output has been sent to the browser.

This will work:
<?
setcookie("moocookie",$moo);
echo $moo;
?>

To debug your problem, go through the code looking for any echo, print, printf (or similar) statements that occur before setcookie(..) or header(..) statements...

02-15-2001, 12:15 AM
I've shrunken the code to this: but I still get the errors. Can Anyone help?

<?
chdir("/home/cavy4me/public_html/forums/");
include("global.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$num_active = 4;
$num_chars = 40;

$query_forum = "select * from forum where forumid='$latest_array[forumid]'";
$result_forum = mysql_query($query_forum,$db);
$forum_info_array = mysql_fetch_array($result_forum);
$querythread="SELECT * FROM post WHERE threadid='$latest_array[threadid]' ORDER BY dateline ASC LIMIT 1";
$result_thread_text= mysql_query($querythread,$db);
$result_thread_array = mysql_fetch_array($result_thread_text);

$querylatest="SELECT * FROM thread WHERE forumid='1' OR forumid='2' OR forumid='3' OR forumid='4' OR forumid='5' OR forumid='6' OR forumid='10' ORDER BY lastpost DESC LIMIT $num_active";

$resultlatest = mysql_query($querylatest,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
if ($newscomments==1) {
$commenttext = "reply";
}
else {
$commenttext = "replies";
}
$newstitle = $latest_array["title"];
$newscomments = $latest_array["replycount"];
$newsthreadid = $latest_array["threadid"];
print("<table width=90%% cellpadding=2 BORDER=0 ALIGN=CENTER><tr><td width=100%% bgcolor=#99CCFF><FONT SIZE=-1><B>Subject: $newstitle</B></FONT><br></td></tr><tr><td width=100%% bgcolor=#f7f7f7><FONT SIZE=-1>Read the <a href=http://www.caviesgalore.com/forums/showthread.php?threadid=$newsthreadid>$newscomments $commenttext</a><br></FONT></td></tr></table>");
}
?>

02-15-2001, 02:13 AM
Delete all the white space before and after your enclosing PHP tags... <? ?>

02-16-2001, 01:03 AM
By whitespace, do you mean double line breaks? Because I did that and it doesn't change anything.

02-16-2001, 01:09 AM
Yes.. All the white space (line breaks, tabs and spaces) in the global.php file has to be eliminated.

Only look at stuff outsie the <? ?> tags.. Don't concern yourself with what is inside.

This isn't a Netscape error.

02-21-2001, 11:51 AM
Yes!!! Thank you so much!! I was having the same problem and removing the white spaces fixed it! Happy dancing here! Can't believe it was that simple!
Tigerlily:)