Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/148305-retrieving-image-location-in-mysql/
Share on other sites

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

 

You output to the browser before you call the header function.  For more detail read here:

 

http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

Hi,

 

I have studied the pages you have suggested. As I understand from the pages, we should not output anything to the browser before the header using the echo function. Is that right? So when I have looked back in the code, I see that the image retrieved is not printed before the header function. So I did not quite understand where the problem is exactly. Also, I have moved the results table part below the image retrieval code(Just to make sure that I haven't output any stuff before the header) But I still get the same problem. I further deleted all the echo statements that are present before the header (like the connection established successfully and query sent successfully statements). I am just posting the new code below to just let you know what I did. What I did may be stupid but please let me know what I could have or should have done.

 

thanks,

Sashi

 

 

<html>
<body>
<form action="image.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="Air Conditioning Facility">Air Conditioning Facility</option>
      <option value="Ambler Johnston Hall">Ambler Johnston Hall</option>
      <option value="Architecture Annex">Architecture Annex</option>
      <option value="Armory">Armory</option>
      <option value="Art and Design Learning Center">Art and Design Learning Center</option>
      <option value="Barringer Hall">Barringer Hall</option>
      <option value="Bio informatics phase I">Bio informatics phase I</option>
      <option value="Bio informatics phase II">Bio informatics phase II</option>
      <option value="Bishop-Favrao Hall">Bishop-Favrao Hall</option>
      <option value="Brodie Hall">Brodie Hall</option>
      <option value="Building 270F">Building 270F</option>
      <option value="Burchard Hall">Burchard Hall</option>
      <option value="Burke Johnston Student Center">Burke Johnston Student Center</option>
      <option value="Burrows/Burleson Tennis Center">Burrows/Burleson Tennis Center</option>
      <option value="Burruss Hall">Burruss Hall</option>
      <option value="War Memorial Hall">War Memorial Hall</option>
      <option value="Whittemore Hall">Whittemore Hall</option>
      <option value="William E. Lavery Health Research Center">William E. Lavery Health Research 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="image.php?">
<?php 
// Connects to your Database
$host="localhost";
$user="root";
$password="prreddy";
$dbname="VT_VPM";
$cxn=mysqli_connect($host, $user, $password, $dbname) ;
if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
{
	$error=mysqli_error($cxn);
	echo "$error";
	die();
}
//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="10:$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);
header('Content-Type: text/html');
$err=1;
if ($img = file_get_contents($location, FILE_BINARY)) 
{
  if ($img = imagecreatefromstring($img)) $err = 0;
}
if ($err) 
{ 
echo 'style="font-size:9px">Error getting image...'; 
} 
else 
{
header('Content-Type: image/jpeg');
  imagejpeg($img);
  imagedestroy($img);
}
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";
?>
</body>
</html>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.