How to display an image stored in Mysql database with special date not by id (php)
<p>I am trying to display an image uploaded to my "upload" table in MySql. I've been reading a lot on how to do this but no luck.</p>

<p>"news_content" table is for uploading NEWS content to Mysql and has 6 columns: id,title, description, content_text, date, time </p>

<p>and "upload" table has 5 columns: id, name, size, image, date</p>

<p>In "news_content" table I upload the date and the time columns separately but the date column in "upload" table is a string concatenated with both date and time. For example if in "news_content" table the date is 2/3/2016 and the time is 5:30, in "upload" table the date is going to be 2/3/20165:30. I organized it that way in order to retrieve the image by its specific date and time that the related post uploaded.  </p>

<p>I upload the image in <em>news.php</em> page with this following code:</p>

<p><strong>news.php :</strong></p>

<pre><code>// Create connection
$connection = mysql_connect("localhost","root","p206405az");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysql_error());
}
//select a database to use
$db_select = mysql_select_db( "news" , $connection) ;
    if (!$db_select) { die("Selection faild:" . mysql_error())  ;
}
//uploading the content of news and date and time
if(isset($_POST["submit"])){

    $title = $_POST["title"] ;
    $description = $_POST["description"] ;
    $content_text  =  $_POST["content_text"]  ;
    $date = $_POST["date"] ;
    $time = $_POST["time"] ;
//perform mysql query
    $result = mysql_query("INSERT INTO news_content (title, description, content_text, date, time)
        VALUES ('$title', '$description', '$content_text' ,'$date' , '$time' )")  ;

    if (!$result) {
        die("Insert failed: " . mysql_error());
        $submitMessage = "Problem with updating the post, please try again" ;

    } else if ($result){

        $submitMessage = "Your post succsessfully updated" ;
    }

}
// uploading the image
if(isset($_POST['submit']) &amp;&amp; $_FILES['image']['size'] &gt; 0)
{
    $fileName = $_FILES['image']['name'];
    $tmpName  = $_FILES['image']['tmp_name'];
    $fileSize = $_FILES['image']['size'];
    $fileType = $_FILES['image']['type'];
    $filedate = "$date" . "$time" ;

    $fp       = fopen($tmpName, 'r');
    $content2 = fread($fp, filesize($tmpName));
    $content3 = addslashes($content2);
    fclose($fp);

    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
    }

    $query = "INSERT INTO upload (name, size, type, image, date ) ".
        "VALUES ('$fileName', '$fileSize', '$fileType', '$content3', '$filedate')";

    mysql_query($query) or die('Error2, query failed');
}
</code></pre>

<p>And I want to retrieve that image by <em>getImage.php</em> page to use it as source page later by this following code but it seems it can't retrieve the blob data:</p>

<p>P.S. The image is successfully uploaded but I can't retrieve it with specific date that I Posted lately </p>

<p><strong>getImage.php :</strong></p>

<pre><code>// Create connection
$connection = mysql_connect("localhost","root","p206405az");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysql_error());
}
//select a database to use
$db_select = mysql_select_db( "news" , $connection) ;
if (!$db_select) { die("Selection faild:" . mysql_error())  ;
}

//perform mysql query

$result = mysql_query("SELECT * FROM news_content" , $connection);
if (!$result) {
    die("read failed: " . mysql_error());
}
//useing returned data
while ($content = mysql_fetch_array($result)){

    $date = $content["date"];
    $time = $content["time"] ;

}

$filedate = "$date" . "$time" ;

$result2 = mysql_query("SELECT image FROM upload WHERE date='$filedate'" , $connection);
if (!$result2) {
    die("read failed: " . mysql_error());
};

$row = mysql_fetch_assoc($result2);
mysql_close($connection);

header("Content-type: image/jpeg");
echo $row['image'];
</code></pre>

<p>And I want to display the image in <em>index.php</em> page with this following HTML code:</p>

<p><strong>index.php :</strong></p>

<pre><code>&lt;img src="getImage.php?date=&lt;?php echo $filedate ; ?&gt;" width="175" height="200" /&gt;
</code></pre>

<p>How can I retrieve that data in <em>getImage.php</em> page and then use that page az source page to display the image in <em>index.php</em> page?
Any help would be appreciated.</p>