title: How to delete an image from folder in PHP and delete file name from phpMyAdmin?
body: <p>I'm a beginner in PHP and what I need to do is delete from my uploads folder as well as deleting a row of information in the database from phpMyAdmin. I know I have to implement an unlink, but I'm not sure how to place it in my code. Any help would be appreciated. Thank you.</p>
  
  <pre><code>$dbc = mysqli_connect('localhost', 'root', 'root', 'myimages');
  
  $files = glob("uploads/*.*");
  
  if (isset($_GET['id']) &amp;&amp; is_numeric($_GET['id']) ) { 
  
  $query = "SELECT title FROM imagedata WHERE id={$_GET['id']}";
  
  if ($r = mysqli_query($dbc, $query)) {
      $row = mysqli_fetch_array($r); 
  
      print '&lt;form action="delete_image.php" method="post"&gt;
      &lt;p style="color: red;"&gt;Are you sure you want to delete this image?&lt;/p&gt;
      &lt;p&gt;&lt;h4&gt;' . $row['title'] . '&lt;/h4&gt;&lt;br&gt;
      &lt;input type="hidden" name="id" value="' . $_GET['id'] . '"&gt;
      &lt;input type="submit" name="submit" value="Delete this image"&gt;&lt;/p&gt;
      &lt;/form&gt;';
  } else { 
      print '&lt;p style="color: red;"&gt;Could not retrieve the image because:&lt;br&gt;' . mysqli_error($dbc) . '.&lt;/p&gt;&lt;p&gt;The query being run was: ' . $query . '&lt;/p&gt;';
  }
  
  } elseif (isset($_POST['id']) &amp;&amp; is_numeric($_POST['id'])) { 
  
  $query = "DELETE FROM imagedata WHERE id={$_POST['id']} LIMIT 1";
  $r = mysqli_query($dbc, $query); 
  
  if (mysqli_affected_rows($dbc) == 1) {
      print '&lt;p&gt;The image has been deleted.&lt;/p&gt;';
  } else {
      print '&lt;p style="color: red;"&gt;Could not delete the image because:&lt;br&gt;' . mysqli_error($dbc) . '.&lt;/p&gt;&lt;p&gt;The query being run was: ' . $query . '&lt;/p&gt;';
  }
  
  } else { 
  print '&lt;p style="color: red;"&gt;This page has been accessed in error.&lt;/p&gt;';
  } 
  
  mysqli_close($dbc);
  </code></pre>