Here is the code I am using to try and retrieve an image from a database:
<?php
if($id)
{
//please change the server name username and password according to your mysql server setting
$mysql_server="localhost";
$mysql_username="myuser";
$mysql_password="mypass";
$mysql_database="mydb";
//connect to database using above settings
@MYSQL_CONNECT("localhost",$mysql_username,$mysql_password);
@mysql_select_db("mydb");
//select the picture using the id
$query = "select bin_data,filetype from todo where id=$id";
//execute the query
$result = @MYSQL_QUERY($query);
//get the picture data which will be binary
$data = @MYSQL_RESULT($result,0,"bin_data");
//get the picture type. It will change according to file extension it may be either gif or jpg
$type = @MYSQL_RESULT($result,0,"filetype");
//send the header of the picture we are going to send
Header( "Content-type: $type");
//send the binary data
echo $data;
};
?>
Instead of displaying the requested image, it displays this icon: (not sure what you call it)... https://i.sstatic.net/16c5e.png
Here are all the columns in my table: https://i.sstatic.net/ravYm.png
I'm pretty positive I'm doing everything right...not sure what's going on. Help anyone? Thanks in advance!
$idis blank so it will never get that far, you should useisset($id) && is_numeric($id)instead.