Page 1 of 1

Dreadful headers already sent!

Posted: Tue Apr 01, 2008 6:47 am
by nVee
Well, this project has given me more problems than i bargained for, but i think once i get the headers already sent out of the way, it will be a straight road too home for me!

AS you can hear, its a headers already sent issue!

Heres the deal. I have images which is directly uploaded into the database. I prefer it this way. Obviously to view it, you must add a header(\"Content-type:image/jpeg\"); but if i add that too my code i get headers already sent and bam, the image goes all funky on me!

Can someone please logically explain to me why this is happening, possible causes and what i am doing wrong. Here is my code:

Code: Select all

 
$sql = mysql_query("SELECT * FROM bushshirts");
     while($row = mysql_fetch_array($sql))
     {
     // get variables
    $name = $row['name'];
     $img = $row['img'];
    $id = $row['id'];
    $description = $row['description'];
  
 
     echo"
    header(\"Content-type:image/jpeg\");
    <table bgcolor='red' border='1px' width='400px'>
     <tr>
     <td width='100px'>$name</td>
     <td width='100px'>$img</td>
     <td width='100px'>$id</td>
     <td width='100px'>$description</td>
     </tr>
     </table><br>";
     }
 
?>
 

Re: Dreadful headers already sent!

Posted: Tue Apr 01, 2008 6:57 am
by EverLearning
To show the images from db your code won't work, because you're echoing HTML, not the image. You need a separate file, which will output the image from db, and which you will call from the within image tag in the list of images.

Read the following tutorial, it has what you need - link

Re: Dreadful headers already sent!

Posted: Tue Apr 01, 2008 8:19 am
by superdezign
Images are not HTML. Images are files. Files are binary data, not XML. You have to create the image as a file, and the reference that particular file in your HTML.

Headers belong at the beginning of a file. That's why we call them headers. The browser receives the headers, then outputs the file data.

Re: Dreadful headers already sent!

Posted: Tue Apr 01, 2008 8:46 am
by samb0057
If you want to output an image, you either have to put it into a separate file and reference that file, or output it directly with no html.

The problem with this code you have here is that you are sending an image/jpeg content type header, but you're also outputting HTML. Mixing two content types in one page will not work.