Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot modify header information - error message

    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

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for your help

    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

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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.

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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.

  • #6
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I cna't find the error, here is my code.

    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.

    Code:
    <!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',status='$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

  • #7
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"])
    Last edited by MRMAN; 05-10-2006 at 11:18 AM.

  • #8
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    PHP Code:
    <? 
    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',status='$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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •