我正在尝试删除数据库中的特定字段(不是整行)。但现在,它并没有删除我数据库中的任何内容。
当用户单击删除按钮时,我想清空保存图像路径的字段。
HTML部分:
<div class="delete_image"><a href="#" id="<?php echo $recipe_path ?>"
class="delete_image">Remove!</a></div>
AJAX 部分:
$('.delete_image').on("click",function()
{
var ID = $(this).attr("id");
var dataString = '$recipe_path='+ ID;
if(confirm("Are you sure you want to delete this image ?"))
{
$.ajax({
type: "POST",
url: "remove.php",
data: dataString,
cache: false,
});
}
return false;
});
PHP部分(remove.php):
<?php
include "includes/db.php";
if ($_POST['recipe_path'])
{
$recipe_path = $_POST['recipe_path'];
$sql = query("DELETE FROM recipes WHERE $recipe_path = '$recipe_path' ");
}
?>
我对 SQL 查询做错了吗?