Warning: Cannot modify header information

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dfm
    New Member
    • Feb 2008
    • 6

    Warning: Cannot modify header information

    Hi, I cant change the header to display images from a database. It's giving me this error :

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/f/m/dfmcons/html/secwhouse/index.php:18) in /home/content/d/f/m/dfmcons/html/secwhouse/index.php on line 71

    Here is the code :
    [php]
    <?
    mysql_connect(" $host","$userna me", "$password" );
    mysql_select_db ("secwhouse" );
    ?>
    <head>
    <title>Securi ty Warehouse Sample Concept</title>
    </head>
    <body>
    <table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <th scope="col"><ta ble width="750" border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <th scope="col"><ob ject classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macrom edia.com/pub/
    shockwave/cabs/flash/swflash.cab#ver sion=7,0,19,0" width="750" height="125">
    <param name="movie" value="secbanne r2.swf" />
    <param name="quality" value="high" />
    <embed src="secbanner2 .swf" quality="high" pluginspage="ht tp://www.macromedia. com/go/getflashplayer" type="applicati on/x-shockwave-flash" width="750" height="125"></embed>
    </object></th>
    </tr>
    </table>
    <table width="750" border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <th scope="col"><fo rm id="mnusrch" name="mnusrch" method="post" action="">
    <table width="750" border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <th scope="col"><in put type="text" name="textfield " /></th>
    <th scope="col"><im g src="images/sec_01.gif" width="72" height="30" /></th>
    <th scope="col"><im g src="images/sec_03.gif" width="359" height="30" /></th>
    <th scope="col"><im g src="images/sec_04.gif" width="74" height="30" /></th>
    <th scope="col"><im g src="images/sec_05.gif" width="98" height="30" /></th>
    </tr>
    </table>
    </form>
    </th>
    </tr>
    </table>
    <table width="750" border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <th scope="col"><im g src="images/menu_01.gif" width="91" height="14" /></th>
    <th scope="col"><im g src="images/menu_02.gif" width="92" height="14" /></th>
    <th scope="col"><im g src="images/menu_03.gif" width="104" height="14" /></th>
    <th scope="col"><im g src="images/menu_04.gif" width="110" height="14" /></th>
    <th scope="col"><im g src="images/menu_05.gif" width="91" height="14" /></th>
    <th scope="col"><im g src="images/menu_06.gif" width="105" height="14" /></th>
    <th scope="col"><im g src="images/menu_07.gif" width="157" height="14" /></th>
    </tr>
    </table>
    <table border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <th scope="col">&nb sp;</th>
    </tr>
    </table>
    <?
    $sql = "SELECT * FROM `prod` WHERE `prod`.`special ` = 'n'";
    $counter=0;
    $result =mysql_query($s ql);
    while($rows=mys ql_fetch_array( $result))
    {
    $count=0;
    while($count<>5 )
    {
    ?>
    <table border="0" cellspacing="0" cellpadding="0" id="main">
    <tr>
    <th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="left1">
    <tr>
    <th scope="col"><? header("Content-type: image/jpeg");echo $rows['image']; ?></th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row"><? echo $rows['prod']; ?></th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row"><? echo $rows['price']; ?></th>
    </tr>
    </table></th>
    <th scope="col">&nb sp;</th>
    <th scope="col"><ta ble border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <?
    $rows=mysql_fet ch_array($resul t);
    ?>
    <th scope="col"><? echo $rows['image']; ?></th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row"><? echo $rows['prod']; ?></th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row"><? echo $rows['price']; ?></th>
    </tr>
    </table></th>
    <th scope="col">&nb sp;</th>
    <th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="right1">
    <tr>
    <th scope="col">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    <tr>
    <th scope="row">&nb sp;</th>
    </tr>
    </table></th><? $count=5 ?>
    </tr>
    </table><? } }?>
    <br />
    <p>&nbsp;</p>
    <p><br />
    </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p></th>
    </tr>
    </table>
    </body>
    </html>
    [/php]I left out the connection details, cos the password is visible

    That is not the only thing you left out. You must enclose all code within the appropriate code tags. Read the Posting Guidelines. - moderator
    Last edited by ronverdonk; Mar 3 '08, 11:23 AM. Reason: code within code tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Post your code again after masking the password, and applying [php] tags.

    Now you have disordered line 18 and 71, the actual culprits.

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Hi,

      The headers have to be set before any output is given. Output includes blank lines in the file. you can process information before the headers are set you just can't write anything to the screen.

      Perhaps that's the problem.

      Cheers
      nathj

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        I cant Even see any headers being sent =/

        Comment

        • nathj
          Recognized Expert Contributor
          • May 2007
          • 937

          #5
          Originally posted by markusn00b
          I cant Even see any headers being sent =/

          Nor can I but I'm guessing there something in the code that was left out.

          Perhaps you could post the full code sample, using tags, but simply change the sesitive data to indicate what shuold be there.

          nathj

          Comment

          • henryrhenryr
            New Member
            • Jun 2007
            • 103

            #6
            Surely line 66

            [code=php]header("Content-type: image/jpeg");[/code]

            is your error...

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by henryrhenryr
              Surely line 66

              [code=php]header("Content-type: image/jpeg");[/code]

              is your error...
              Indeed it is. :D

              Can't believe i missed that :(

              Ohwell, move that line to the beggining of your script.

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by markusn00b
                Indeed it is. :D

                Can't believe i missed that :(

                Ohwell, move that line to the beggining of your script.

                NO!!! Its not an image file!

                Instead of <? header("Content-type: image/jpeg");echo $rows['image']; ?>, write <img src="<?php echo $rows['image']; ?>"></img>

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  *If $rows['image'] referrers to the name of the image file.

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by hsriat
                    NO!!! Its not an image file!

                    Instead of <? header("Content-type: image/jpeg");echo $rows['image']; ?>, write <img src="<?php echo $rows['image']; ?>"></img>
                    Calm down.
                    I was tired last night ¬_¬

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Originally posted by markusn00b
                      Calm down.
                      I was tired last night ¬_¬
                      I'm calm :)
                      And the OP isn't back!

                      Comment

                      • dfm
                        New Member
                        • Feb 2008
                        • 6

                        #12
                        [PHP]<?
                        $host="******";
                        $username="**** **";
                        $password="**** ***";
                        $dbname="secwho use";
                        mysql_connect(" $host","$userna me", "$password" );
                        mysql_select_db ("$dbname");
                        header("Content-type: image/jpeg");
                        ?>[/PHP[HTML]]<head>
                        <title>Securi ty Warehouse Sample Concept</title>
                        </head>
                        <body>
                        <table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
                        <tr>
                        <th scope="col"><ta ble width="750" border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                        <th scope="col"><ob ject classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macrom edia.com/pub/shockwave/cabs/flash/swflash.cab#ver sion=7,0,19,0" width="750" height="125">
                        <param name="movie" value="secbanne r2.swf" />
                        <param name="quality" value="high" />
                        <embed src="secbanner2 .swf" quality="high" pluginspage="ht tp://www.macromedia. com/go/getflashplayer" type="applicati on/x-shockwave-flash" width="750" height="125"></embed>
                        </object></th>
                        </tr>
                        </table>
                        <table width="750" border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                        <th scope="col"><fo rm id="mnusrch" name="mnusrch" method="post" action="">
                        <table width="750" border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                        <th scope="col"><in put type="text" name="textfield " /></th>
                        <th scope="col"><im g src="images/sec_01.gif" width="72" height="30" /></th>
                        <th scope="col"><im g src="images/sec_03.gif" width="359" height="30" /></th>
                        <th scope="col"><im g src="images/sec_04.gif" width="74" height="30" /></th>
                        <th scope="col"><im g src="images/sec_05.gif" width="98" height="30" /></th>
                        </tr>
                        </table>
                        </form>
                        </th>
                        </tr>
                        </table>
                        <table width="750" border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                        <th scope="col"><im g src="images/menu_01.gif" width="91" height="14" /></th>
                        <th scope="col"><im g src="images/menu_02.gif" width="92" height="14" /></th>
                        <th scope="col"><im g src="images/menu_03.gif" width="104" height="14" /></th>
                        <th scope="col"><im g src="images/menu_04.gif" width="110" height="14" /></th>
                        <th scope="col"><im g src="images/menu_05.gif" width="91" height="14" /></th>
                        <th scope="col"><im g src="images/menu_06.gif" width="105" height="14" /></th>
                        <th scope="col"><im g src="images/menu_07.gif" width="157" height="14" /></th>
                        </tr>
                        </table>
                        <table border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                        <th scope="col">&nb sp;</th>
                        </tr>
                        </table>[/HTML] [PHP] <?
                        $sql = "SELECT * FROM `prod` WHERE `prod`.`special ` = 'n'";
                        $counter=0;
                        $result =mysql_query($s ql);
                        while($rows=mys ql_fetch_array( $result))
                        {
                        $count=0;
                        while($count<>5 )
                        {
                        ?>[/PHP] [HTML] <table border="0" cellspacing="0" cellpadding="0" id="main">
                        <tr>
                        <th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="left1">
                        <tr>
                        <th scope="col">[/HTML[PHP]]<? echo $rows['image']; ?>[/PHP[HTML]]</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">[/HTML[PHP]]<? echo $rows['prod']; ?>[/PHP][HTML]</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">[/HTML][PHP]<? echo $rows['price']; ?>[/PHP][HTML]</th>
                        </tr>
                        </table></th>
                        <th scope="col">&nb sp;</th>
                        <th scope="col"><ta ble border="0" cellspacing="0" cellpadding="0" >
                        <tr>[/HTML]
                        [PHP]<?
                        $rows=mysql_fet ch_array($resul t);
                        ?>[/PHP][HTML] <th scope="col">[/HTML][PHP]<? echo $rows['image']; ?>[/PHP][HTML]</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">[/HTML][PHP]<? echo $rows['prod']; ?>[/PHP][HTML]</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">[/HTML][PHP]<? echo $rows['price']; ?>[/PHP][HTML]</th>
                        </tr>
                        </table></th>
                        <th scope="col">&nb sp;</th>
                        <th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="right1">
                        <tr>
                        <th scope="col">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        <tr>
                        <th scope="row">&nb sp;</th>
                        </tr>
                        </table></th>[/HTML][PHP]<? $count=5 ?>[/PHP]
                        [HTML]</tr>
                        </table>[/HTML][PHP]<? } }?>[/PHP]
                        [HTML] <br />
                        <p>&nbsp;</p>
                        <p><br />
                        </p>
                        <p>&nbsp;</p>
                        <p>&nbsp;</p>
                        <p>&nbsp;</p></th>
                        </tr>
                        </table>
                        </body>
                        </html>[/HTML]

                        THANKS FOR ALL THE REPLIES, I MOVED THE HEADER CODE TO THE BEGINNING OF THE SCRIPT, THE ERROR IS GONE BUT THE IMAGE DOESN'T DISPLAY , IT JUST SHOWS FUNNY CHARACTERS!!!!!

                        Comment

                        • dfm
                          New Member
                          • Feb 2008
                          • 6

                          #13
                          [php]<?
                          $host="******";
                          $username="**** **";
                          $password="**** ***";
                          $dbname="secwho use";
                          mysql_connect(" $host","$userna me", "$password" );
                          mysql_select_db ("$dbname");
                          header("Content-type: image/jpeg");
                          ?><head>
                          <title>Securi ty Warehouse Sample Concept</title>
                          </head>
                          <body>
                          <table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
                          <tr>
                          <th scope="col"><ta ble width="750" border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                          <th scope="col"><ob ject classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macrom edia.com/pub/shockwave/
                          cabs/flash/swflash.cab#ver sion=7,0,19,0" width="750" height="125">
                          <param name="movie" value="secbanne r2.swf" />
                          <param name="quality" value="high" />
                          <embed src="secbanner2 .swf" quality="high" pluginspage="ht tp://www.macromedia. com/go/getflashplayer" type="applicati on/x-shockwave-flash" width="750" height="125"></embed>
                          </object></th>
                          </tr>
                          </table>
                          <table width="750" border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                          <th scope="col"><fo rm id="mnusrch" name="mnusrch" method="post" action="">
                          <table width="750" border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                          <th scope="col"><in put type="text" name="textfield " /></th>
                          <th scope="col"><im g src="images/sec_01.gif" width="72" height="30" /></th>
                          <th scope="col"><im g src="images/sec_03.gif" width="359" height="30" /></th>
                          <th scope="col"><im g src="images/sec_04.gif" width="74" height="30" /></th>
                          <th scope="col"><im g src="images/sec_05.gif" width="98" height="30" /></th>
                          </tr>
                          </table>
                          </form>
                          </th>
                          </tr>
                          </table>
                          <table width="750" border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                          <th scope="col"><im g src="images/menu_01.gif" width="91" height="14" /></th>
                          <th scope="col"><im g src="images/menu_02.gif" width="92" height="14" /></th>
                          <th scope="col"><im g src="images/menu_03.gif" width="104" height="14" /></th>
                          <th scope="col"><im g src="images/menu_04.gif" width="110" height="14" /></th>
                          <th scope="col"><im g src="images/menu_05.gif" width="91" height="14" /></th>
                          <th scope="col"><im g src="images/menu_06.gif" width="105" height="14" /></th>
                          <th scope="col"><im g src="images/menu_07.gif" width="157" height="14" /></th>
                          </tr>
                          </table>
                          <table border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                          <th scope="col">&nb sp;</th>
                          </tr>
                          </table>
                          <?
                          $sql = "SELECT * FROM `prod` WHERE `prod`.`special ` = 'n'";
                          $counter=0;
                          $result =mysql_query($s ql);
                          while($rows=mys ql_fetch_array( $result))
                          {
                          $count=0;
                          while($count<>5 )
                          {
                          ?>
                          <table border="0" cellspacing="0" cellpadding="0" id="main">
                          <tr>
                          <th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="left1">
                          <tr>
                          <th scope="col"><? echo $rows['image']; ?></th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row"><? echo $rows['prod']; ?></th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row"><? echo $rows['price']; ?></th>
                          </tr>
                          </table></th>
                          <th scope="col">&nb sp;</th>
                          <th scope="col"><ta ble border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                          <?
                          $rows=mysql_fet ch_array($resul t);
                          ?>
                          <th scope="col"><? echo $rows['image']; ?></th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row"><? echo $rows['prod']; ?></th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row"><? echo $rows['price']; ?></th>
                          </tr>
                          </table></th>
                          <th scope="col">&nb sp;</th>
                          <th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="right1">
                          <tr>
                          <th scope="col">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          <tr>
                          <th scope="row">&nb sp;</th>
                          </tr>
                          </table></th><? $count=5 ?>
                          </tr>
                          </table><? } }?>
                          <br />
                          <p>&nbsp;</p>
                          <p><br />
                          </p>
                          <p>&nbsp;</p>
                          <p>&nbsp;</p>
                          <p>&nbsp;</p></th>
                          </tr>
                          </table>
                          </body>
                          </html>[/php]

                          I moved the header code to the beginning of the script , the error is gone but it doesn't display the image, it just displays funny characters! please help,
                          Last edited by ronverdonk; Mar 3 '08, 01:09 PM. Reason: make up text

                          Comment

                          • Markus
                            Recognized Expert Expert
                            • Jun 2007
                            • 6092

                            #14
                            Look at post #8

                            And dont type in caps.

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              Don't overdo you tags now. Just one pair at start and end of your code suffices.

                              moderator

                              Comment

                              Working...