Reputation: 437
I'm trying to make a database that uploads the pictures and shows them, sorta like a gallery. It uploads them but the problem is where the pictures should be it gives me this strange symbol ( sorry can't post it because I'm new :| ) and I can't tell if this means it just refuses to show them, or something went wrong. Help?
<?php
mysql_connect("localhost") or die(mysql_error());
mysql_select_db("images") or die(mysql_error());
$id=addslashes($_REQUEST['id']);
$image=mysql_query("SELECT * FROM dadsda WHERE id=$id");
$image=mysql_fetch_assoc($image);
$image=$image['image'];
header("Content-type: image/jpeg");
print($image);
?>
Upvotes: 0
Views: 319
Reputation: 180065
At no point in that code is the image actually output.
If image
is a BLOB
field in the database, you'd need to do print $image;
after the header()
call. If it's a filename/path, you'd need to use readfile()
to output the contents of that file.
Also, this code is vulnerable to SQL injection. If I go to script.php?id=1%3B+DROP+TABLE+dadsda%3B
it'll delete your database table because I just made your code execute the SQL query SELECT * FROM dadsda WHERE id=1; DROP TABLE dadsa;
.
Upvotes: 3
Reputation: 84
sometimes if the image box is empty my jpeg is not defined in your mime types on server side.. just right click on the empty image box and give me the properties... regards..
Upvotes: -2