nac1987 Posted February 26, 2012 Share Posted February 26, 2012 I must be doing something incredibly daft, because I'm incredibly new at this. I have an image stored in a DB under a table called 'images' and I want to display it on my website but instead of that image I get the error: Warning: Cannot modify header information - headers already sent by (output started at /home/... This is how I'm trying to achieve it. Any ideas where I'm doing wrong? Thanks. <?php $user="###"; $password="###"; $database="###"; $con = mysql_connect(localhost,$user,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>MySite</title> </head> <body> <div id="container"> <?php include("../navbar.php"); ?> <div id="left-content"></div> <div id="right-content"> <?php $item = $_GET['item']; $query = "SELECT * FROM main WHERE Ref='$item'"; $result = mysql_query($query) or die("Oops" .mysql_error()); $row = mysql_fetch_array($result,MYSQL_BOTH) or die("Oops" .mysql_error()); extract($row); $query2 = "SELECT image FROM main WHERE Ref='$item'"; // the result of the query $result2 = mysql_query($query2) or die("Invalid query: " . mysql_error()); header("Content-type: image/jpg"); echo mysql_result($result2, 0,'image'); echo "<p><strong>Name: </strong>".$FirstName." - ".$SecondName."</p>"; mysql_close($con); ?> </div> <br /> <?php include("../footer.php"); ?> </div> </div> </body> </html> MOD EDIT: . . . BBCode tags added. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Read the sticky topic titled, "HEADER ERRORS - READ HERE BEFORE POSTING THEM". Quote Link to comment Share on other sites More sharing options...
nac1987 Posted February 26, 2012 Author Share Posted February 26, 2012 I am sorry. I'll remember the code tags for future postings. I've just read the other thread. I'm still a bit at a loss. A lot of the code you see there is just typed in from a book, I don't fully understand what a header is. Should this bit of code that states that the variable is a jpg image This bit: header("Content-type: image/jpg"); Is that different to a <head> </head> section of a web page? Ignorance isn't bliss. Quote Link to comment Share on other sites More sharing options...
litebearer Posted February 26, 2012 Share Posted February 26, 2012 http://stackoverflow.com/questions/5753928/how-to-display-multiple-images-blob-from-mysql-using-php Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 In short, you cannot have any output sent to the browser before an http header is sent (which is what header() does). HTML markup is output. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.