我正在尝试通过 jQuery 和 AJAX 更新数据库条目。我正在检查我发送的值是否正确 - 但我不确定如何检查数据库未更新的原因。
我的代码如下:
$(document).on("click", ".approve", function(){
var classes = $(this).parents('div:eq(0)'); // this gets the parent classes.
i = 0;
var pros = [];
classes.find(".prosncons .pros ul li").each(function(){
pros.push($(this).text());
});
var cons = [];
classes.find(".prosncons .cons ul li").each(function(){
cons.push($(this).text());
});
var notes = classes.find(".notes").text();
var id = classes.find(".id").text();
var data = "method=approve&pros="+pros+"&cons="+cons+"¬es="+notes+"&id="+id;
$.ajax({
type: "POST",
url: "../scripts/upload.php",
data: data,
success: $(this).closest(".approval").remove(),
});
});
PHP::
if($method == "approve"){
$sql = "UPDATE `approval` SET approved = 1 WHERE pros=:pros, cons=:cons, notes=:notes, id=:id";
$statement = $conn->prepare($sql);
$statement->execute(array(':pros' => $pros, ':cons' => $cons, ':notes' => $notes, ':id'=> $id));
}