How to delete image form folder and database

0 votes

With the code below, I'm displaying data from a MySQL database in a Table.

<td><?php echo $row['name']; ?></td>
			<td><?php echo $row['image']; ?></td>
			<a title="Delete" href="deletestudent.php?id=<?php echo $row['id']; ?>"><button class="btn btn-danger btn-mini"> Delete</button></a></td>

The first row displays the picture name, while the second row displays the image that is located inside the images directory.
I can delete the row using the code below:

<?php
	include('../connect.php');
	$id=$_GET['id'];
	$result = $db->prepare("DELETE FROM student WHERE id= :memid");
	$result->bindParam(':memid', $id);
	$result->execute();
	
	header ("location: students.php");
?>

But I also want to remove one image from the Images folder. How can I do that?

Jul 26, 2022 in PHP by Kithuzzz
• 38,000 points
1,480 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
You should first delete the image, and then if that goes well, delete the image from the database. The unlink function in PHP allows you to remove the picture. Check that the file is present first.

I hope this helps you.
answered Jul 28, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In PHP

0 votes
0 answers

How to upload image and save path to database?

I have a page with some displayed ...READ MORE

Jul 22, 2022 in PHP by Kithuzzz
• 38,000 points
914 views
0 votes
1 answer

How to validate E-mail and URL of Php form?

hey, The code below shows a simple way ...READ MORE

answered Feb 13, 2020 in PHP by manish
2,484 views
0 votes
1 answer

How to delete all files from a folder using PHP?

Hello @kartik, Use this: $files = glob('path/to/temp/*'); // get ...READ MORE

answered Sep 14, 2020 in PHP by Niroj
• 82,840 points
1,497 views
0 votes
1 answer

How to upload and delete files from dropzone.js?

Hello, For deleting thumbnails you have to enable ...READ MORE

answered Nov 4, 2020 in PHP by Niroj
• 82,840 points
10,518 views
0 votes
0 answers

How to display image from database using PHP?

I want to display an image from ...READ MORE

May 11, 2022 in PHP by Kichu
• 19,040 points
1,041 views
0 votes
0 answers

How to retrieve images from MySQL database and display in an html tag

I created a table using the  BLOB column ...READ MORE

Jun 19, 2022 in PHP by narikkadan
• 63,600 points
1,543 views
0 votes
0 answers

How to convert date into timestamp in SQL query?

I'm attempting to move data from the ...READ MORE

Aug 19, 2022 in Database by Kithuzzz
• 38,000 points
1,888 views
0 votes
1 answer
0 votes
1 answer

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in.

The issue is that the query given to mysqli_query() is ...READ MORE

answered May 1, 2022 in Other DevOps Questions by narikkadan
• 63,600 points
1,859 views
0 votes
0 answers

Creating a search form in PHP [duplicate]

I am working on a function where ...READ MORE

Jun 9, 2022 in PHP by Kichu
• 19,040 points
492 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP