I'm learning php and mysql. Right now I need some help with delete image using $_GET method. I can unlink image from folder but not from database column. Here is my database structure for
user_id| username| email| password| department| position| first_name|
last_name| status| user_pic| join_date| modified
// select image from db to delete
$select_img = mysql_query("SELECT user_pic FROM userinfo WHERE user_pic
//delete from db
mysql_query("DELETE FROM userinfo WHERE user_id=".$_GET['delete_id']);
window.alert('Delete images Success!!!');
// here is the HTML part Which display using while loop
<a class="btn close" href="?delete_id=<?php echo $userpic; ?>" title="click
for delete" onclick="return confirm('sure to delete ?')" >×</a>
<img src="assets/img/user_images/<?php echo $userpic; ?>" />
DELETE FROM deletes the entire row.
I'm pretty sure it refuses because of
foreign keys or something.
If you only want to empty the column, you should use
$query = "UPDATE userinfo SET user_pic='' WHERE user_id='$_GET['delete_id']'"; mysql_query($query);
You should also listen to what the others are saying and think about switching to MYSQLI, but more importantly, preventing SQL injection!