title: Inserting Image to MySQL Database
body: <p>I am working on a solution that will help me submit specific images from a list of images to a MySQL Database.</p>
  
  <p>My database consists of the following:</p>
  
  <h2>Database</h2>
  
  <ul>
  <li>id(INT)</li>
  <li>photo(BLOB) </li>
  <li>caption(VAR)</li>
  </ul>
  
  <h2>Code</h2>
  
  <p>I am first retreiving images from a list and giving them each a submit button.</p>
  
  <pre><code>foreach ($media-&gt;data as $data) {
    echo $pictureImage = "&lt;img src=\"{$data-&gt;images-&gt;thumbnail-&gt;url}\"&gt;";
    echo "&lt;form action='tag.php' method='post'&gt;";
    echo "&lt;input type='submit' name='submit' value='Click Me'&gt;";  
    echo "&lt;/form&gt;";
  }
  </code></pre>
  
  <p>$pictureImage parses the data URL and then puts it into an actual image.
  The submit button is below each of those images.</p>
  
  <p>I am then making it so that when the submit button is pressed, it is added to the database.</p>
  
  <pre><code>if(isset($_POST['submit'])) {
    //Database code would be above the following
    $sql="INSERT INTO $usertable (image) VALUES ('$pictureImage')";
  }
  </code></pre>
  
  <h2>Problem</h2>
  
  <p>I am running into an issue where the last image in my list is the one being submitted to the database, rather than the image with the corresponding submit button. How do I make it so that it is grabbing the photo with the corresponding submit button? </p>
  
  <p>Any help would be appreciated greatly.</p>