gpt4 book ai didi

javascript - PHP 文件无法从 Jquery ajax 读取多个参数

转载 作者:行者123 更新时间:2023-12-03 05:49:00 25 4
gpt4 key购买 nike

我已经阅读了该问题的多种解决方案,但似乎没有一个适合我。我有两个文件 manageadmin.php 和rejectaction.php 。 Manageadmin.php 文件为用户提供了一个拒绝管理员的按钮。当某人单击拒绝按钮时,管理员状态必须设置为零。

这是我的初始代码

manageadmin.php

<script type="text/javascript">
$(document).ready(function()
{
/* reject */
$(".reject_btn").click(function(){

var element = $(this);
var reject_id = element.attr('reject_id');
$.ajax({
type: "POST",
url: "rejectaction.php",
data: {reject_id:reject_id},
success: function(){
alert("Reject Successful");
location.reload();
}
});

});
});
</script>

拒绝操作.php

    $reject_id=$_POST['reject_id'];
$reject_query="UPDATE tbl_admin set admin_status=0 where admin_id='$reject_id'";
mysql_query($reject_query);

这工作正常,但后来我意识到我需要多个页面的拒绝代码。所以我想到将where条件中的表名、要更新的列和要检查的列作为参数传递。这是修改后的代码:

<script type="text/javascript">
$(document).ready(function()
{
/* reject */
$(".reject_btn").click(function(){

var element = $(this);
var reject_id = element.attr('reject_id');
var tbl_name = "tbl_admin";
var column_reject = "admin_status";
var column_cond = "admin_id";
$.ajax({
type: "POST",
url: "rejectaction.php",
data: {reject_id:reject_id, tbl_name:tbl_name,
column_cond:column_cond,
column_reject:column_reject},
success: function(){
alert("Reject");
location.reload();
}
});

});
});
</script>

拒绝操作.php

    $reject_id=$_POST['reject_id'];

$tbl_name = $_POST['tbl_name'];
$column_cond = $_POST['column_cond'];
$column_reject = $_POST['column_reject'];

$reject_query="UPDATE '$tbl_name' set '$column_reject' = 0 where '$column_cond'='$reject_id'";


// $reject_query="UPDATE tbl_admin set admin_status=0 where admin_id='$reject_id'";
mysql_query($reject_query);

此代码不起作用(即状态未更新)。但是 alert("Reject Success") 正在执行。我是初学者。有人能指出我所犯的错误吗?谢谢

最佳答案

除了您在评论中收到的(好的)建议之外[另请参阅此答案],您的主要问题可能是您包装了 $table_name, $column_reject 和引号之间的 $column_cond

你应该写:

$reject_query =
"UPDATE $tbl_name set $column_reject = 0 where $column_cond='$reject_id'";

关于javascript - PHP 文件无法从 Jquery ajax 读取多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40222081/

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