gpt4 book ai didi

php - 仅针对特定字段的删除查询问题

转载 作者:太空宇宙 更新时间:2023-11-03 12:26:10 26 4
gpt4 key购买 nike

我正在尝试删除数据库中的特定字段(不是整行)。但现在,它并没有删除我数据库中的任何内容。

当用户点击删除按钮时,我想清空包含图像路径的字段

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 查询有问题吗?

最佳答案

不应该是

$sql = query("DELETE FROM recipes WHERE recipe_path = '$recipe_path' ");

为什么是 $recipe_path

还要确保在页面准备就绪后运行该函数。

$(function(){
$('.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;
});
});

如前所述,DELETE 将删除整行。

关于php - 仅针对特定字段的删除查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com