我需要知道如何刪除$ imagenes形式的路徑在我的數據庫...我不能做到這一點成功(在數據庫是成功刪除)...我已經把取消鏈接代碼,但在錯誤日誌中顯示我的圖像的ID,但不是圖像的名稱...這是我的PHP代碼:如何刪除圖像,當我刪除與PDO的MySQL數據庫的路徑
--- EDITED-- -
所以我不知道如何使它在該id(idToDelete)中刪除$ imagenes ...我可以在之前或之後選擇表?或者是沒有必要的
下面是表
- id_imagen(INT PK)
- imagenes(VARCHAR 100)
- id_paciente(INT FK)
- f_imagen(CURRENT_TIMESTAMP )
在personal.php我的形象和與Ajax調用我嘗試將其刪除:
/*the styles of del button and wrapper */
<style type="text/css">
.del_wrapper{float:right;}
.content_wrapper {
max-width: 100%;
margin-right: auto;
margin-left: auto;
}
</style>
/*the ajax call */
<script type="text/javascript">
$(document).ready(function() {
$("body").on("click", "#gallery .del_button", function(e)
{
e.returnValue = false;
var clickedID = this.id.split('-');
var DbNumberID = clickedID[1];
var myData = 'recordToDelete='+ DbNumberID;
jQuery.ajax({
type: "POST",
url: "delimage.php?ts=" + new Date().getTime(),
dataType:"text",
data:myData,
success:function(response){
$('#item_'+DbNumberID).fadeOut("slow");
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
});
</script>
/*the image gallery */
<div id="gallery">
<?
$sql = $conn->prepare("select * from IMAGENES where id_paciente = $_GET[id_paciente] order by id_imagen ASC");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
$id_imagen = $row['id_imagen'];
$imagenes = $row['imagenes'];
echo "<div class='del_wrapper' id='item_".$row['id_imagen']."'><a href='#' class='del_button' id='del-".$row['id_imagen']."'>";
echo "<img src='../images/icon_del.gif' border='0' />";
echo "</a>";
echo "<a href='../$imagenes' class='group4'>";
echo "<img src='../$imagenes' class='image_thumbnail' />";
echo "</a> </div>";
}
?></div>
和代碼delimage.php與選擇:
<?
include_once("config.php");
if(isset($_POST["recordToDelete"]) && strlen($_POST["recordToDelete"])>0 && is_numeric($_POST["recordToDelete"]))
{
$stmt=$conn->prepare("SELECT id_imagen,imagenes FROM IMAGENES where id_imagen = $_GET[id_imagen]");
$result = $conn->query($sql);
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$recordToDelete=$data['imagenes'];
unlink("../imagenes/$imagenes");
}
$idToDelete = filter_var($_POST["recordToDelete"],FILTER_SANITIZE_NUMBER_INT);
if($stmt=$conn->prepare("delete from IMAGENES WHERE id_imagen=$idToDelete"))
$stmt->bindParam("$idToDelete",$id_imagen,PDO::PARAM_INT);
$stmt->execute();
$dbh = null;
}
?>
ajax調用的作品,因爲在提琴手我看到圖像的id將刪除它在delimage.php,但只有d elete以dB爲單位,而不是圖像的路徑imagenes文件夾內
你不能混合使用$ POST []和$ GET []。你使用什麼取決於FORM方法 –