当用户单击“取消”按钮时,我遇到了问题。当用户单击“取消”按钮时,我希望它通过导航到 cancelimage.php 页面来删除数据库中的一行。但它不会删除已上传但随后取消的文件的数据库行。通过查看下面的代码,为什么它不从数据库中删除该行以及如何对其进行编码以便它删除?
下面是开始上传的 startImageUpload() 函数以及取消按钮功能的特色:
function startImageUpload(imageuploadform){
...
$(".imageCancel").on("click", function(event) {
var image_file_name = $(this).attr('image_file_name');
jQuery.ajax("cancelimage.php" + image_file_name)
.done(function(data) {
$(".imagemsg" + _cancelimagecounter).html(data);
});
return stopImageUpload();
});
return true;
}
下面是cancelimage,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["fileImage"]["name"];
echo "File Upload was Canceled";
$imagecancelsql = "DELETE FROM Image
WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($image_file_name)."'";
mysql_query($imagecancelsql);
mysql_close();
?>
下面是插入数据库行的 php 脚本 (imageupload.php):
<?php
session_start();
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$result = 0;
move_uploaded_file($_FILES["fileImage"]["tmp_name"],
"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
$imagesql = "INSERT INTO Image (ImageFile)
VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
mysql_query($imagesql);
mysql_close();
?>