Dreadful headers already sent!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nVee
Forum Newbie
Posts: 11
Joined: Mon Mar 31, 2008 9:44 am

Dreadful headers already sent!

Post 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>";
     }
 
?>
 
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Dreadful headers already sent!

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Dreadful headers already sent!

Post 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.
samb0057
Forum Commoner
Posts: 27
Joined: Wed Mar 26, 2008 9:51 am

Re: Dreadful headers already sent!

Post 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.
Post Reply