Hi Sashi: You're incurring in this error because the headers for the page have already been issued in the head section of your page. When you issue the php header() function, it will generate an error. Anyway, you are storing a path to a file in the database. My question is: do you want to put your images on a subfolder of your site, where they will become acessible through regular URLS, or you want to keep them private and only accessible by scripting? Cheers. JP -----Original Message----- From: Sashikanth Gurram <sashi34u@xxxxxx> To: php-db@xxxxxxxxxxxxx Subject: Re: Retrieving Image Location in MySQL Date: Fri, 06 Mar 2009 12:23:31 -0500 Dear all, I have been trying to retrieve the location of a image from database and display the image in the browser using PHP. I have written a sort of code for the purpose. All I am getting in my browser after using the code is a long set of ASCII characters with the following warning *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *237 * I am herewith attaching my code. If anyone can point out the error or give some kind of advice that would be really great. The location of the image is stored in a table by the name IMAGE under the column name Location and here in the code, the location is retrieved under the varibale name $Location. thanks, Sashi /<html> <body> <form action="mysqli.php" method="post"> <br> <div align="center"> Building Name:<select name="name"> <option value=""> Select a Building</option> <option value="Agnew Hall">Agnew Hall</option> <option value="Rector Field House">Rector Field House</option> <option value="Richard B. Talbot Educational Resources Center">Richard B. Talbot Educational Resources Center</option> <option value="Robeson Hall">Robeson Hall</option> <option value="Sandy Hall">Sandy Hall</option> <option value="Saunders hall">Saunders hall</option> <option value="Seitz Hall">Seitz Hall</option> <option value="Shanks Hall">Shanks Hall</option> <option value="Shultz Hall">Shultz Hall</option> <option value="Skelton Conference Center">Skelton Conference Center</option> <option value="Williams Hall">Williams Hall</option> <option value="Women's Softball Field">Women's Softball Field</option> <option value="Wright House">Wright House</option> </select> </div> <input type="submit" /> </form> <img src="mysqli.php?"> <?php // Connects to your Database $host="*******"; $user="*****"; $password="******"; $dbname="*******"; $cxn=mysqli_connect($host, $user, $password, $dbname) ; if (!$cxn=mysqli_connect($host, $user, $password, $dbname)) { $error=mysqli_error($cxn); echo "$error"; die(); } else { echo "Connection established successfully"; } //Define the variables for Day and Month $Today=date("l"); $Month=date("F"); $build=$_POST["name"]; $low_speed=2.5; $high_speed=4; $hour=date("G"); $minute=date("i"); if ($minute>=00 && $minute<=14) { $minute=00; } elseif ($minute>=15 && $minute<=29) { $minute=15; } elseif ($minute>=30 && $minute<=44) { $minute=30; } else { $minute=45; } $times="$hour:$minute"; $sql="SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times'"; $data = mysqli_query($cxn,$sql); if (!$data=mysqli_query($cxn,$sql)) { $error=mysqli_error($cxn); echo "$error"; die(); } else { echo "<br>"; echo "Query sent successfully"; } echo "<br>"; echo "<h1> PARKING LOT INFORMATION <h1>"; echo "<table border='1' cellspacing='5' cellpadding='2'>"; echo "<tr>\n <th>Building</th>\n <th>Parking Lot</th>\n <th>Estimated Number of Empty Spaces</th>\n <th>Distance (Feet)</th>\n <th>Estimated walking time to the building</th>\n </tr>\n"; while ($row=mysqli_fetch_array($data)) { extract($row); $building = $row[0]; $parking_lot = $row[1]; $Number_of_Empty_Spaces = $row[2]; $Distance = $row[3]; $time_l = $row[4]; $time_h=$row[5]; $location=$row[6]; echo "<tr>\n <td>$building</td>\n <td>$parking_lot</td>\n <td>$Number_of_Empty_Spaces</td>\n <td>$Distance</td>\n <td>$time_h - $time_l mins</td>\n <td>$location</td>\n </tr>\n"; } echo "</table>\n"; $err=1; if ($img = file_get_contents($location, FILE_BINARY)) { if ($img = imagecreatefromstring($img)) $err = 0; } if ($err) { header('Content-Type: text/html'); echo '<html><body><p style="font-size:9px">Error getting image...</p></body></html>'; } else { header('Content-Type: image/jpeg'); imagejpeg($img); imagedestroy($img); } ?> </body> </html>/ Sashikanth Gurram wrote: > Hello guys, > > Thanks to you all for your kind replies. I will try the steps and get > back to you if I encounter more problems. > > Thanks, > Sashi > > Fortuno, Adam wrote: >> Matya, >> >> Ha, ha, ha! Thank you good friend. I did say I didn't try the code :-) >> >> AF> Please note, I haven't tried this. It just seems plausible. >> >> I apologize if I confused anyone. I just meant to show how the >> parameter could help retrieve a picture. I wasn't too concerned with >> the particulars. Hopefully the concept is sound. If not, please do >> flame my note so no one attempts it. >> >> Be Well, >> A- >> >> -----Original Message----- >> From: Mattyasovszky Janos [mailto:mail@xxxxxxxx] Sent: Monday, March >> 02, 2009 9:29 AM >> To: php-db@xxxxxxxxxxxxx >> Subject: Re: Retrieving Image Location in MySQL >> >> Fortuno, Adam írta: >> >> >>> //Write a query to pull out the picture's path >>> $sql = "SELECT path FROM Image WHERE ID = %s"; >>> mysql_real_escape_string($value); >>> >> >> Sorry, but this won't work, since you don't map the value of the >> escaped $value to the %s, lets say with sprintf()... >> >> Regards, >> Matya >> >> > > -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php