Forum Moderators: coopster
<?php
$username = "user";
$password = "pass";
$host = "localhost";
$database = "binary";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$id = $_GET['id'];
if(!isset($id) || empty($id)){
die("Please select your image!");
}
else{
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
}
?>
<?php
$username = "user";
$password = "pass";
$host = "localhost";
$database = "binary";
//assign connection handle
$conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
mysql_select_db($database, $conn) or die("Can not select the database: ".mysql_error());
//assign and clean the $_GET variable
$id_number = ((isset($_GET['id']) && !empty($_GET['id'])) ? strip_tags($_GET['id']) : '');
//you never know
if($id_number == ""){
echo "No number was selected";
exit;
}
//set up the query & clean (not necessary, but matter of habit :))
$query_db = "SELECT * FROM `tbl_images` WHERE `id` ='".mysql_real_escape_string($id_number)."' ";
//execute query
$query = mysql_query($query_db) or die(mysql_error());
//if returns more than one row
if(mysql_num_rows($query) > 0){
//loop through results
while($row = mysql_fetch_array($query)){
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
}
else{
//no matches
echo "Sorry, no records found";
//sleep long enough for the message to be displayed
sleep(2);
//back to form no records found
header("location: yoursitehere");
exit;
}
?>
<?php
$username = "user";
$password = "pass";
$host = "localhost";
$database = "binary";
$conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
mysql_select_db($database) or die("Can not select the database: ".mysql_error());
if(isset($_GET['id']) && !empty($_GET['id']) && ctype_digit($_GET['id'])){
$id_number = strip_tags($_GET['id']);
$query_db = "SELECT * FROM `tbl_images` WHERE `id` = ".mysql_real_escape_string($id_number)." LIMIT 1";
$query = mysql_query($query_db) or die(mysql_error());
if(mysql_num_rows($query) > 0){
while($row = mysql_fetch_array($query)){
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
}//while
}//second if
else{
echo "No results returned";
exit;
}
}//first if
else{
echo "No number selected please try again";
exit;
}
?>