Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009

    Unanswered: Retrieving Image Location in MySQL

    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.


    <form action="mysqli.php" method="post">
    <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>
                       <input type="submit" />
    <img src="mysqli.php?">
    // Connects to your Database
    $cxn=mysqli_connect($host, $user, $password, $dbname) ;
    if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
           echo "$error";
           echo "Connection established successfully";
    //Define the variables for Day and Month
    if ($minute>=00 && $minute<=14)
    elseif ($minute>=15 && $minute<=29)
    elseif ($minute>=30 && $minute<=44)
    $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))
           echo "$error";
           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>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
    while ($row=mysqli_fetch_array($data))
    $building = $row[0];
         $parking_lot = $row[1];
         $Number_of_Empty_Spaces = $row[2];
         $Distance = $row[3];
         $time_l = $row[4];
         $location=$row[6];   echo "<tr>\n
                 <td>$parking_lot</td>\n               <td>$Number_of_Empty_Spaces</td>\n
                 <td>$time_h - $time_l mins</td>\n
       echo "</table>\n";
    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>';
     header('Content-Type: image/jpeg');

  2. #2
    Join Date
    Mar 2007
    You CANNOT do

    header('Content-Type: text/html');
    header('Content-Type: image/jpeg');

    If you have already output (i.e. echo'd) some content. Headers MUST be sent before any output. The error indicates this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts