1

我有来自 ajax 调用的 PHP 变量。但是,当他们通过 if 语句和 while 循环时,它们是未定义的,我该如何解决这个问题。我什么都做不了。

$userID = $_POST['id'];
$clubID = $_POST['clubID'];
$type = $_POST['type'];
$delAtt = $_POST['delAtt'];

其余代码

if($delAtt == 1)
{
    $result = mysql_query('SELECT * FROM events WHERE clubID = "'.$clubID.'"');

    while ($row == mysql_fetch_assoc($result))
    {

        $eventID = $row['eventID'];
        echo $eventID;

         mysql_query('DELETE FROM eventmember WHERE userID = "'.$userID.'" AND eventID = "'.$eventID.'"');
         mysql_query('DELETE FROM eventmember2 WHERE userID = "'.$userID.'" AND eventID = "'.$eventID.'"');
         mysql_query('DELETE FROM eventmember3 WHERE userID = "'.$userID.'" AND eventID = "'.$eventID.'"');

         mysql_query('DELETE FROM attendance WHERE userID = "'.$userID.'" AND eventID = "'.$eventID.'"');
         mysql_query('DELETE FROM attendance2 WHERE userID = "'.$userID.'" AND eventID = "'.$eventID.'"');
         mysql_query('DELETE FROM attendance3 WHERE userID = "'.$userID.'" AND eventID = "'.$eventID.'"');

     }
}

所有变量都在 if 语句内工作,但不在 while 循环内

4

2 回答 2

2
if(isset($_POST['delAtt'])){
    $userID = $_POST['id'];
    $clubID = $_POST['clubID'];
    $type = $_POST['type'];
    $delAtt = $_POST['delAtt'];
}
else{
    $delAtt = 0
}

// Rest of code

并正确分配这一行:

while ($row == mysql_fetch_assoc($result)){
            ^

至:

while ($row = mysql_fetch_assoc($result)){
于 2013-08-24T19:10:28.697 回答
0

您可以随时检查 POST 变量,如下所示:

if (isset($_POST["id"]) && !empty($_POST["id"])) { //TO DO }

这样您就更容易知道您的 POST 变量是否真的发布到接收页面。

以下代码可以向您展示 POST 变量数组中的内容。

print_r($_POST);
于 2013-08-24T19:11:21.873 回答