首页 > 解决方案 > 更新仅更新所选数据的动态图像

问题描述

我很难解决我的代码面临的问题。而不是仅仅更新我应该编码的记录,例如,我只是要更新我的“谷歌旅游套餐”的图像,而不是仅仅更新它的图像,它会更新所有记录,所以发生的事情就是我的数据库中的图像都是一样的。我认为问题出在 where 子句上。

这是在 xammp v3.2.2 中运行 sql 和 apache 的 windows 服务器

  $targetDir = "../../../../../../img/itinerary/";
  $fileName = basename($_FILES["itinerary_img"]["name"]);
  $targetFilePath = $targetDir . $fileName;
  $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
  $itinerary_id = $_GET['id'];

    if(!empty($_FILES["itinerary_img"]["name"]))
    {
        $allowTypes = array('jpg','png','jpeg','gif','pdf');
        if(in_array($fileType, $allowTypes))
        {
            if(move_uploaded_file($_FILES["itinerary_img"]["tmp_name"], 
            $targetFilePath))
            {
                // Insert image file name into database
                $insert ="UPDATE 'tms_itinerary' SET itinerary_img =    ".$fileName."' WHERE itinerary_id = '".$itinerary_id."' ";

               $result2 = mysqli_query($mysqli, $insert);

                if($result2){
                    $statusMsg = "The file ".$fileName. " has been uploaded successfully.";
                }else{
                    $statusMsg = "File upload failed, please try again.";
                }
            }else{
                $statusMsg = "Sorry, there was an error uploading your file.";
            }
        }else{
            $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.';
        }
    }else{
       $statusMsg = 'Please select a file to upload.';
    }

我希望输出仅更改我正在更新的图像,而不是所有 itinerary_image

标签: javascriptphphtmlcsssql

解决方案


推荐阅读