douxian5963 2012-05-06 21:55
浏览 44
已采纳

如何在此示例中删除数据库行?

I have a problem when the user has clicked on the "Cancel" button. When the user clicks on the "Cancel" button, I want it to delete a row in the database by navigating to the cancelimage.php page. But it is not deleting the database row of the file which has been uploaded but then canceled. By looking at the code below, why is it not deleting the row from the database and how can it be coded so that it does?

Below is the startImageUpload() function where it starts uploading and where the cancel button function is featured:

    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;
            }

Below is the cancelimage,php page where it is suppose to delete a row from the database?

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


?>

Below is the php script (imageupload.php) where it inserts a database row:

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

?>
  • 写回答

1条回答 默认 最新

  • dtvhqlc57127 2012-05-06 22:05
    关注

    Looking at your code, I'm pretty sure there would be nothing in the $_FILES variable on the call to cancelimage.php

    What you could do is pass the name of the image as a parameter to the cancelimage.php script and the use that in your query.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测