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();

?>
4

1 回答 1

2

看起来你的 SQL 语法有点不对劲。试试这个:

$imagedeletesql = "DELETE FROM Image 
    WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($image_file_name)."'";
于 2012-05-06T01:02:34.173 回答