...

View Full Version : Cannot modify header information - error message



harlequeen
05-08-2006, 06:08 PM
I have a page (next) which pulls in some detail from a database, which are then made into active links, clicking on one brings up the complete record in a form (comletelist) so that it can be edited. Pressing the save button updates the record and then should redirect to the page (next)with the original list, giving a 'database updated' message and displaying the active links again.

The database is updating, but I don't get my confirmation message, only the error message below.


Warning: Cannot modify header information - headers already sent by (output started at /chroot/home/TM340484/public_html/blog/completelist.php:18) in /chroot/home/TM340484/public_html/blog/completelist.php on line 87

I did search for this error, but nothing I found made any sense to me. Can anyone help me with this.

cheers

harlequeen:(

marek_mar
05-08-2006, 06:40 PM
http://www.codingforums.com/showpost.php?p=300877&postcount=6

harlequeen
05-08-2006, 08:32 PM
Thanks, I looked at that, but being a newbie, I don't really understand what I have to do to correct it.

I went through the code taking out any blank lines that followed any <php tags, but that didn't correct it.

I am trying to teach myself by doing little projects, and I'm sure I used this type of redirection before, but my knowledge is so basic that I don't know what I need to do here.

Thanks for your help anyway.

Harlequeen

Nightfire
05-08-2006, 10:11 PM
You must be outputting something to the browser before you're setting the headers somewhere. That's the only time you'll be getting that error.

Beagle
05-08-2006, 10:20 PM
completelist.php:18

Check out line 18 of this file. It would appear it's outputting something, using echo, or print, or perhaps it's generating an error and outputting the error message to the screen.

harlequeen
05-10-2006, 11:05 AM
I have looked and looked at this, in light of everyone's comments, but just can't find it. I am wondering if there is a fundamental error in my code (below)

Perhaps somebody can look at it and spot what is wrong. Being so new to this its difficult for me to spot things which may not be picked up in the magazines and books I am using to learn this.

Hope you cna help, thanks in advance.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>p l a b l o g </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="test.css">
<link rel="stylesheet" href="pblog.css" type="text/css" />
</head>

<body>
<div id="pagewidth">
<div id="header">
</div>
<div id="wrapper" class="clearfix">
<div id="twocols" class="clearfix">
<div id="maincol">

<div class="photobox">
<?php
$article_id=$_GET['article_id'];
include("myconnect.php");
$editresult = mysql_query("SELECT * FROM article WHERE article_id='$article_id'");
?>
<h3>Edit Current/Archived Articles</h3>
<?php
while ($myrow = mysql_fetch_array($editresult))
{


?>
<form name="edit" method="POST" action="completelist.php">

<input type="hidden" name="article_id" value= "<?php echo $myrow["article_id"]; ?>" >

<input type="hidden" name="article_top_id" value= "<?php echo $myrow["article_top_id"]; ?>" >
<p><b>Title</b><br>

<input type="text" name="article_title" size="60" maxlength="60" value="<?php echo $myrow["article_title"]; ?>">

<br><b>Article Text</b> <br>
<textarea name="article_text" cols="45" rows="12" wrap="on"><?php echo $myrow["article_text"]; ?></textarea>

<input type="hidden" name="article_date" size="12" maxlength="12" value="<?php echo $myrow["article_date"]; ?>">


<br><b>Associated Image</b> <br>
<input type="text" name="article_imagelink" size="60" maxlength="60" value="<?php echo $myrow["article_imagelink"]; ?>">

<p><b>Current Status</b><br>
Current <input type="radio" name="status" value="C" <?php if ($myrow["status"]=="C") { echo "checked"; } ?>>
Archived <input type="radio" name="status" value="A" <?php if ($myrow["status"]=="A") { echo "checked"; }?>>

<?php
}// end while
?>
<input type="submit" value="Save" name="Save" ><br>

</form>
<?php
if ($HTTP_POST_VARS ["Save"])
{
include("myconnect.php");

$article_id=$HTTP_POST_VARS['article_id'];
$article_top_id=$HTTP_POST_VARS['article_top_id'];
$article_title=$HTTP_POST_VARS['article_title'];
$article_text=$HTTP_POST_VARS['article_text'];
$article_date=$HTTP_POST_VARS['article_date'];
$article_imagelink=$HTTP_POST_VARS['article_imagelink'];
$status=$HTTP_POST_VARS['status'];



$editquery =("UPDATE article SET article_id='$article_id', article_top_id='$article_top_id',article_title='$article_title', article_text='$article_text',article_date='$article_date',article_imagelink='$article_imagelink',sta tus='$status' WHERE article_id='$article_id'");

$result=mysql_query($editquery);
if ($result) {
header ('Location: next.php?confirm=Article has successfully updated');
}//end if result
else {
echo "<b>ERROR: unable to post.</b>";
}//end else

}//end first if

echo "<p><p>You entered the <strong>following</strong> information:<br>";
echo "<b>article_id:</b> $article_id<br>";
echo "<b>article_top_id:</b> $article_top_id<br>";
echo "<b>article_title:</b> $article_title<br>";
echo "<b>article_text:</b> $article_text<br>";
echo "<b>article_date:</b> $article_date<br>";
echo "<b>article_imagelink:</b> $article_imagelink<br>";
echo "<b>status:</b> $status<br>";

?>
</div>

</div>
<div id="rightcol" > <?php require_once('rightnav.htm'); ?>
</div>
</div>
<div id="leftcol" > <?php require_once('leftnav.htm'); ?>
</div>
</div>
<div id="footer" > Copyright: &copy; Harlequeen 2006
</div>
</div>

</body>
</html>

I had closed up all the spaces previously and tried that, but for ease of seeing the code have spaced it out again.

Cheers

Harlequeen

MRMAN
05-10-2006, 11:16 AM
sorry my mistake.
line 78 you have a header call. but before that you have loads of out puts that appear before the
if ($HTTP_POST_VARS ["Save"])

harlequeen
05-10-2006, 11:46 AM
Are the form elements the outputs? I have to echo the myrow stuff in order that the user will be able to see what they want to amend. If I can't output this information, I can't see how I can do this.

Thanks for your patience.

MRMAN
05-10-2006, 12:51 PM
Yes the form element are out puts.
the header is triggered when the data is stored into the database, but why is is needed because that header will take a user to a different page.
If they are meant to go to a different page then you can do this.


<?
if($HTTP_POST_VARS ["Save"])
{
include("myconnect.php");

$article_id=$HTTP_POST_VARS['article_id'];
$article_top_id=$HTTP_POST_VARS['article_top_id'];
$article_title=$HTTP_POST_VARS['article_title'];
$article_text=$HTTP_POST_VARS['article_text'];
$article_date=$HTTP_POST_VARS['article_date'];
$article_imagelink=$HTTP_POST_VARS['article_imagelink'];
$status=$HTTP_POST_VARS['status'];

$editquery =("UPDATE article SET article_id='$article_id', article_top_id='$article_top_id',article_title='$article_title', article_text='$article_text',article_date='$article_date',article_imagelink='$article_imagelink',sta tus='$status' WHERE article_id='$article_id'");

$result=mysql_query($editquery);
if ($result) {
header ('Location: next.php?confirm=Article has successfully updated');
}//end if result
else {
$message = "<b>ERROR: unable to post.</b>";
}
}
else
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>p l a b l o g </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="test.css">
<link rel="stylesheet" href="pblog.css" type="text/css" />
</head>

<body>
<div id="pagewidth">
<div id="header">
</div>
<div id="wrapper" class="clearfix">
<div id="twocols" class="clearfix">
<div id="maincol">

<div class="photobox">
<?php
$article_id=$_GET['article_id'];
include("myconnect.php");
$editresult = mysql_query("SELECT * FROM article WHERE article_id='$article_id'");
?>
<h3>Edit Current/Archived Articles</h3>
<?php
while ($myrow = mysql_fetch_array($editresult))
{


?>
<form name="edit" method="POST" action="completelist.php">

<input type="hidden" name="article_id" value= "<?php echo $myrow["article_id"]; ?>" >

<input type="hidden" name="article_top_id" value= "<?php echo $myrow["article_top_id"]; ?>" >
<p><b>Title</b><br>

<input type="text" name="article_title" size="60" maxlength="60" value="<?php echo $myrow["article_title"]; ?>">

<br><b>Article Text</b> <br>
<textarea name="article_text" cols="45" rows="12" wrap="on"><?php echo $myrow["article_text"]; ?></textarea>

<input type="hidden" name="article_date" size="12" maxlength="12" value="<?php echo $myrow["article_date"]; ?>">


<br><b>Associated Image</b> <br>
<input type="text" name="article_imagelink" size="60" maxlength="60" value="<?php echo $myrow["article_imagelink"]; ?>">

<p><b>Current Status</b><br>
Current <input type="radio" name="status" value="C" <?php if ($myrow["status"]=="C") { echo "checked"; } ?>>
Archived <input type="radio" name="status" value="A" <?php if ($myrow["status"]=="A") { echo "checked"; }?>>

<?php
}// end while
?>
<input type="submit" value="Save" name="Save" ><br>

</form>
</div>

</div>
<div id="rightcol" > <?php require_once('rightnav.htm'); ?>
</div>
</div>
<div id="leftcol" > <?php require_once('leftnav.htm'); ?>
</div>
</div>
<div id="footer" > Copyright: &copy; Harlequeen 2006
</div>
</div>

</body>
</html>

<?
}
?>


what that will do is if "Save" is set then is will enter the data into the database and then redirect the page to next.php.
if its not set then it will show the form elements.

Hope this is what you are after. if not then i will be glad to help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum