1
我想要做的是,當用戶點擊「刪除」按鈕時,它將從服務器上刪除文件,並刪除存儲相同文件名的數據庫行。現在,文件從服務器上成功刪除,那不是問題。如何在這個例子中從數據庫中刪除一行?
問題是,它不是刪除存儲相同文件名的數據庫行。我怎樣才能實現它?
下面是刪除按鈕,導航到deleteimage.php的javascript函數:
var counter = 0;
function stopImageUpload(success, imagefilename){
counter++;
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
var _counter = counter;
$('.listImage').eq(window.lastUploadImageIndex).find(".deletefileimage").on("click", function(event) {
var image_file_name = $(this).attr('image_file_name');
jQuery.ajax("deleteimage.php?imagefilename=" + image_file_name)
.done(function(data) {
$(".imagemsg" + _counter).html(data);
});
$(this).parent().remove();
});
return true;
}
下面是deleteimage.php:
<?php
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die("Unable to select database");
$image_file_name = $_GET["imagefilename"];
echo "$image_file_name was Deleted";
unlink("ImageFiles/$image_file_name");
$imagedeletesql = "DELETE FROM Image (ImageFile)
WHERE ('ImageFile = ImageFiles/". mysql_real_escape_string($image_file_name)."')";
mysql_query($imagedeletesql);
mysql_close();
?>
謝謝你的回答:) – user1373827