title: How to save Image from one table into another via php?
body: <p>I have two separate tables in my database. One for raw Images and other for Labelled Images. I want it to behave like this:</p>
  
  <ol>
  <li>A random Image is obtained from first database on the front end using following query:</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;form
    &lt;div class="col-4 col-12-small"&gt;
                          &lt;input type="radio" id="radio-Fear" name="radio" value="7"&gt;
                          &lt;label for="radio-Fear"&gt;Fear&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class="col-4 col-12-small"&gt;
                            &lt;input type="radio" id="radio-Sadness" name="radio" value="8"&gt;
                            &lt;label for="radio-Sadness"&gt;Sadness&lt;/label&gt;
                          &lt;/div&gt;
                        &lt;/br&gt;
                          &lt;ul class="actions"&gt;
                  &lt;li&gt;&lt;input type="submit" name="submit" value="submit" class="button primary fit" /&gt;&lt;/li&gt;
                             &lt;li&gt;&lt;a href="label_images.php" class="button"&gt;Skip&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="index.html" class="button"&gt;Quit&lt;/a&gt;&lt;/li&gt;
                 &lt;/ul&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Connection String:</p>
  
  <pre><code>$user = "root";
  $pass = "";
  $db1 = "raw_images";
  $db2 = "labelled_images";
  $conn1 = mysqli_connect('localhost',$user,$pass,$db1);
  $conn2 = mysqli_connect('localhost',$user,$pass,$db2);
  if(!$conn1||!$conn2)
  {
  die(mysqli_error());
  }
  </code></pre>
  
  <p>Image Retrieval from first database:</p>
  
  <pre><code>   &lt;div class="image fit"&gt;
     &lt;?php
     //Connection with DB
  
     $sql = "SELECT * FROM tbl_raw_image WHERE id IN
      (SELECT id FROM (SELECT id FROM tbl_raw_image ORDER BY RAND() LIMIT 1) t)";
     $sth = $conn1-&gt;query($sql);
     $result=mysqli_fetch_array($sth);
     $id=$result['id'];
     $image=$result['image'];
     echo '&lt;img src="data:image/jpeg;base64,'.base64_encode( $image ).'"/&gt;'; ?&gt;
         &lt;/div&gt;
  </code></pre>
  
  <p>Image storing in second database:</p>
  
  <pre><code>if(isset($_POST['submit'])){
  
  $label=$_POST['radio'];
  $query2="INSERT INTO tbl_labelled_image(image, label, id_in_raw_image_table) VALUES('$image','$label','$id'); ";
  $rs  = mysqli_query($conn2, $query2);
  }
  </code></pre>