Jump to content


help


5 replies to this topic

#1 venomsnake

    Jedi In Training

  • Members
  • PipPip
  • 481 posts
  • Gender:Male

Posted 09 October 2005 - 03:37 PM

i need more help please :)

its a header error, but i cant figure out whats wrong, im trying to add a comment to news, but it gives me a error, and when i go back to look at the news and what comments are on it, it only shows the name, not the comment

Quote

Warning: Cannot modify header information - headers already sent by (output started at /home/cory/domains/gamingreloaded.com/public_html/newscomments/news.php:5) in /home/cory/domains/gamingreloaded.com/public_html/newscomments/news.php on line 53

<?php
include 'dbconnect.php';
$sql = mysql_query("SELECT * FROM news WHERE id = ".$_GET['id']);
if($sql == 0){
echo "<br /><br />Cannot Find News Item. <a href=\"show.php\">Go Back?</a>";
}else{
while($r=mysql_fetch_assoc($sql))
{
$id=$r["id"];
$title=$r["title"];
$newstext=$r["newstext"];
$postdate=$r["postdate"];
$icon=$r["icon"];
$username=$r["username"];
$news = nl2br("$newstext");
echo "<img src=\"$icon\" class=\"newsicon\" alt=\"\" /> \n";
echo "<br /><b>:: $title</b> // Posted By <b>$username</b><br /> \n Posted on <b>$postdate</b><br class=\"clear\" /> \n";
echo "$news<br class=\"clear\" /><br /> \n";
}}
?>
<b>Comments:</b><br />
<?php
$sql = mysql_query("SELECT * FROM comments WHERE commentid = ".$_GET['id']);
if($sql == 0){
echo "<b>No Comments Yet</b>.";
}else{
while($r=mysql_fetch_assoc($sql))
{
$comment=$r["comment"];
$commentauthor=$r["commentauthor"];
$comment1 = htmlspecialchars("$shout1", ENT_QUOTES);
$comments2 = nl2br("$comment1");
echo "<div>:: $commentauthor</div> \n";
echo "<div>$comments2</div> \n";
}}
?>
<?php
if($_POST['comments'])
{
if (empty($_POST['commentauthor'])) {
echo"You Forgot To Enter A Name! Please <a href=\"javascript:history.go(-1);\">Go Back</a> And Add One!";
exit; }
elseif (empty($_POST['comment'])) {
echo"You Forgot To Enter A Message! Please <a href=\"javascript:history.go(-1);\">Go Back</a> And Add One!";
exit; }
elseif ($_POST['commentauthor'] == "Nickname") {
echo"You Forgot To Enter A Name! Please <a href=\"javascript:history.go(-1);\">Go Back</a> And Add One!";
exit; }
elseif ($_POST['comment'] == "Comment") {
echo"You Forgot To Enter A Message! Please <a href=\"javascript:history.go(-1);\">Go Back</a> And Add One!";
exit; }
$result=MYSQL_QUERY("INSERT INTO comments (commentauthor,commentid,comment)"."VALUES ('$commentauthor','$commentid','$comment')");
header("Location: ". $_SERVER['HTTP_REFERER']);
}
?>
<form action="<?php echo"{$_SERVER['PHP_SELF']}" ?>" method="post">
<p>
<input onfocus="if (value=='Nickname') value='';" onblur="if(value=='') value='Nickname';" size="50" type='text' value='Nickname' name='commentauthor' maxlength='100' />
<textarea onfocus="if (value=='Nickname') value='';" onblur="if(value=='') value='Nickname';" name="comment" rows="5" cols="50">Comment</textarea>
<input class="hide" type="hidden" name="commentid" value="<?php $echoit=$_GET['id']; echo"$echoit"; ?>" />
<input type="submit" name="comments" value="Add Tag" />
</p>
</form>

line 5:
echo "<br /><br />Cannot Find News Item. <a href=\"show.php\">Go Back?</a>";

and line 53:
header("Location: ". $_SERVER['HTTP_REFERER']);


#2 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 09 October 2005 - 03:51 PM

At the top put
ob_start();
and at the bottom put
ob_flush();


#3 venomsnake

    Jedi In Training

  • Members
  • PipPip
  • 481 posts
  • Gender:Male

Posted 09 October 2005 - 04:11 PM

where at? <_>

#4 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 09 October 2005 - 05:15 PM

I said at the top put
ob_start();
And at the bottom put
ob_flush();


#5 trancedm

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 09 October 2005 - 06:35 PM

this error occur because the header() function must be called before any actual output is sent, also make sure you dont have any whitespaces before and at the end of your script

as HaloprO suggested used the output buffering to fix this problem or you could also use javascript meta refresh

#6 Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 09 October 2005 - 07:17 PM

http://php.net/manua...tion.header.php

This has been asked before, by you actually... please try a search next time. :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users