php_mysql problem image display from database
I am trying to display an image from my database using PHP & MySQL. I have searched in the internet how to do that and I tied it with code I found but the only thing that is appeared in the screen is a file broken or something like that.
My code is:
<?php
if( ( isset($_POST['submitdisplay'] ) )&&( $_POST['pwdADMIN']=="admin1986"))
{
$findm = mysql_query("SELECT idmeasure, vmanufacturer, vmodel, vtype, volume, yearofvehicle, motion, timereact,time_0_18m,
time_0_100m, time_0_200m, time_0_300m, time_0_400m, speedexit, time_0_100km, typeoftyre, dmeasure, temperature, sceneryofmeasure,
horsepower, vehicleforce, drivername, email, emailappearornot, sitelink, stock, weightofvehicle, videoofvehicle, comments, password
FROM measurementofvehicle WHERE approved='NO'");
echo '<table border="2" style="width: 100%; align: center;" bordercolor="red">';
$tmpid="";
while ($row = mysql_fetch_array($findm, MYSQL_NUM))
{
echo '<tr>';
echo '<td align="center"><font color="red">';echo $row[0];echo '</font></td>';
$tmpid=$row[0];
echo '<td align="center"><font color="red">';echo $row[1];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[2];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[3];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[4];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[5];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[6];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[7];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[8];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[9];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[10];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[11];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[12];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[13];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[14];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[15];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[16];开发者_运维问答echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[17];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[18];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[19];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[20];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[21];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[22];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[23];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[24];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[25];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[26];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[27];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[28];echo '</font></td>';
echo '<td align="center"><font color="red">';echo $row[29];echo '</font></td>';
$idr = "";
$getidr = "SELECT fidRtime FROM measurementofvehicle_receiptoftime_receiptofforce_imageofvehicle WHERE fidmeasure='$tmpid'";
$r1 = mysql_query($getidr)or die(mysql_error());
while($srow = mysql_fetch_array($r1) )
{
$idr=$srow['fidRtime'];
}
echo "$idr";
echo "<img src=\"GetImage.php?id=$idsr\">\n";
echo '</tr>';
}
echo '</table>';
}
?>
I retrieve the id of the image from another table,
$Receiptoftime = "CREATE TABLE Receiptoftime(
idRtime INT NOT NULL AUTO_INCREMENT,
nameRtime VARCHAR(30) NOT NULL,
typeRtime VARCHAR(30) NOT NULL,
sizeRtime INT NOT NULL,
contentRtime MEDIUMBLOB NOT NULL,
PRIMARY KEY(idRtime)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
idRtime
is the id I need to retrieve the id from the table that it's stores the image.
That table is
$Receiptoftime = "CREATE TABLE Receiptoftime(
idRtime INT NOT NULL AUTO_INCREMENT,
nameRtime VARCHAR(30) NOT NULL,
typeRtime VARCHAR(30) NOT NULL,
sizeRtime INT NOT NULL,
contentRtime MEDIUMBLOB NOT NULL,
PRIMARY KEY(idRtime)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
The code I found I see that I had to write a script that generates the image and then use the tag image so that I can't get the image. The script that generates that image is,
<?php
error_reporting(0);
$connect=mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("dragtimesgr") or die(mysql_error());
$id=addlashes($_REQUEST['id']);
$image=mysql_query("SELECT * FROM receiptoftime WHERE idRtime='$id'")or die(mysql_error());
$image=mysql_fetch_assoc($image);
$image=$image['contentRtime'];
header("Content-type: image/jpeg");
echo $image;
?>
Can you help me? The only thing that appears in the screen is an icon, that seems to be broken. I can't understand what I am doing wrong.
Can you call the image script directly from your browser, e.g. by typing http://host/path/GetImage.php?id=1
or whatever into the browser's location bar?
(Also, you need to fix that script so it isn't such a big injection attack target!)
精彩评论