Display image from index.php?id=xxx

I want to be able to display an image (blob) by grabbing the id in the URL index.php?id= and comparing to the query results (mysql_fetch_array). Essentially, I want to display the image that corresponds to the $_GET id.

First of all, you would get the ID:

[php]if(isset($_GET[‘id’])) { // Check the user set the ID
$id = mysql_real_escape_string($_GET[‘id’]); // Stop SQL injection
} else {
$id = 0; // Some default ID
}[/php]

Then you would run a query to get the image:

[php]$query = mysql_query(“SELECT * FROM some_table WHERE some_table.id = '” . $id . “’”);

if($query != false) {
if(mysql_num_rows($query) == 1) {
$record = mysql_fetch_array($query);
echo ‘’;
} else {
// Record not found
}
} else {
// DB Query failed
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service