title: want to show the newly uploaded image on page reload and page refreshing
body: <p>I have a form in which I have an upload button and a remove button.</p>
  
  <p>Initially an image is displaying on the form which I am retrieving from database (Mysql). </p>
  
  <p>And when I am uploading a new image, the image gets uploaded but the previous image (which is the initial image) also gets displayed on the box.</p>
  
  <p>When I am refreshing the page or reloading it then no image is shown,what I am getting is a box without any image (i.e of initial image). </p>
  
  <p>I want to make that uploaded image shown always until new image is uploaded or removed and also to remove that box of my initial image. How can I do that in php?
  This code is showing initial image when opening my form and till i am not updating:</p>
  
  <pre><code>// Connection to Database 
  $result1= mysql_query( "SELECT images FROM $table" ) or die("SELECT Error".mysql_error()); 
  $row=mysql_fetch_array($result1);
  echo "&lt;img src='data:images/jpeg;base64," .base64_encode( $row['images'])."'width='100' height='100' /&gt;";
  </code></pre>
  
  <p>This is the code to upload the image:</p>
  
  <pre><code>$UPLOADDIR = "upload/";
  if(isset($_POST['Submit']))
  {
          foreach ($_FILES as $key =&gt; $value)
          {
              $image_tmp = $value['tmp_name'];
              $image = $value['name'];
              $image_file = "{$UPLOADDIR}{$image}";
              if(move_uploaded_file($image_tmp,$image_file))
          {
                   mysql_select_db($database) or die("Unable to select database");
               $result1= mysql_query( "SELECT images FROM $table WHERE images='$image'" )or die("SELECT Error: ".mysql_error()); 
           $sql="DELETE FROM $table WHERE ID!=1";
           mysql_select_db($database) or die("Unable to select database");
           $ret=mysql_query($sql,$conn);
           if(!$ret)
          {
               die(mysql_error());
          }
                  $query = "INSERT INTO $table (images) VALUES ('$image')";
          $data = mysql_query ($query)or die(mysql_error());
          echo &lt;&lt;&lt;HEREDOC
                  &lt;div style="float:left;margin-right:10px;"&gt;
                  &lt;img src="{$image_file}" alt="file not found" height="100"         width="100"/&gt;            
                  &lt;/br&gt;
                  &lt;/div&gt;
                  HEREDOC;
          }
          else
         {
              echo "&lt;h1&gt;image file upload failed, image too big after compression&lt;/h1&gt;";
         }
      }
  }
  else
  {
      ?&gt; 
      &lt;form name='newad' method='post' enctype='multipart/form-data' action=''&gt;
      &lt;table&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;input type='file' name='image'&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;input name='Submit' type='submit' value='Upload image'&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
      &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>My uploaded image is saving in database and uploaded image is shown after clicking on upload button but when I reload the page or open the form again then there is no image.</p>