PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
Here is the code that selects the image from the db:
<?php
// some basic sanity checks
if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) {
//connect to the db
$link = mysql_connect("localhost", "", "") or die("Could not connect: " . mysql_error());
// select our database
mysql_select_db("people") or die(mysql_error());
// get the image from the db
$sql = "SELECT Picture FROM people WHERE ID=" . $_GET['image_id'];
// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
// set the header for the image
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
// close the db link
mysql_close($link);
}
else {
echo 'Please use a real id number';
}
?>
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
Is that code you posted in the original post the source code from the entire page? What's happening is the browser isn't realizing how to display the data it's receiving. That happens because the headers sent don't match the data. I see you're sending the Content-type header, but there must be other headers being sent earlier. Do you have any spaces at the beginning of the file, or in any included files?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
The code I am getting in the original post is what when i go to the img src from the image tag: i.e image.php?image_id=181. I have a file which imports from that php and the headers I have in that are
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.