我正在尝试使用ajax删除图像。它显示数据已被删除的警报消息,但在表格中记录仍然存在。如何从表格中删除图像记录...
<span><input type="submit" id="del_btn" value="Delete Image" /></span>
<script type="text/javascript">
$(document).ready(function () {
$("input#del_btn").click(function(){
$.ajax({
type: "POST",
url: "del.php", //
data: {id: <?php echo $delid; ?>},
success: function(msg){
alert("Image Deleted from database");
},
error: function(){
alert("failure");
}
});
});
});
</script>
这是del.php文件
<?php
if (isset($_POST['id'])) {
$imgid = $_POST['id'];
$con=new PDO("mysql:host=localhost;dbname=newimg","root","");
$sql = "DELETE FROM attempt010 WHERE id='$imgid' ";
$con->execute($sql);
}
?>