gpt4 book ai didi

php - 单击取消按钮后如何删除数据库行

转载 作者:行者123 更新时间:2023-11-28 16:18:28 26 4
gpt4 key购买 nike

我想在用户单击取消按钮时删除包含文件名的数据库行。问题是它没有删除数据库行。我做错了什么,数据库行没有被取消?

下面是该表单的相关代码:

var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" + 
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +
"</p><p class='imagef1_cancel' align='center'><label>" +
"<input type='button' name='imageCancel' class='imageCancel' value='Cancel' /></label>" +
"<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");

下面是 startImageUpload() 函数,它启动文件上传并存储取消按钮函数:

  function startImageUpload(imageuploadform, imagefilename){
$('.imagef1_cancel').eq(window.lastUploadImageIndex).find(".imageCancel").on("click", function(event) {
return stopImageUpload(2);
});
return true;
}

下面是 stopImageUpload() 函数,它使用 success 和 result 显示取消消息:

function stopImageUpload(success, imagefilename){
var result = '';
if (success == 2){
result = '<span class="imagecemsg"> The file upload was canceled!</span><br/><br/>';
} else {
result = '<span class="imageemsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}

最后是 imageupload.php 脚本,它使用 iframe 链接到 QandATable.php(包含上面代码的脚本),这就是应该从中删除数据库行的位置:

<?php
session_start();
...//connected to DB
$result = 0;

if ($result == 2) {
$imagecancelsql = "DELETE FROM Image
WHERE ImageFile = 'ImageFiles/".
mysql_real_escape_string($_FILES['fileImage']['name'])."'";
mysql_query($imagecancelsql);
}
mysql_close();
?>
<script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');</script>

最佳答案

在 imageupload.php 中您声明:

$result = 0;

然后你说:

if ($result == 2)...

$result 是 0 而不是 2,因此查询不会被执行。

关于php - 单击取消按钮后如何删除数据库行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10606925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com