Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除时未更新MySQL行_Php_Mysql - Fatal编程技术网

Php 删除时未更新MySQL行

Php 删除时未更新MySQL行,php,mysql,Php,Mysql,我正在从表Accounts中删除一个行用户,并尝试将Count和Follower Count后面的值设置为减去一的值。但出于某种原因,这并没有发生。帐户删除成功,但未发生递减 请告诉我我做错了什么: $query = mysql_query("SELECT * FROM `Accounts` WHERE `Username` = '$username' AND `Password` = '$password' AND `Email Address` = '$emailAdd'"); if

我正在从表Accounts中删除一个行用户,并尝试将Count和Follower Count后面的值设置为减去一的值。但出于某种原因,这并没有发生。帐户删除成功,但未发生递减

请告诉我我做错了什么:

$query = mysql_query("SELECT * FROM `Accounts` WHERE `Username` = '$username' AND `Password` = '$password' AND `Email Address` = '$emailAdd'");
    if (mysql_num_rows($query) < 1) {
        exit("Account doesn't exist");
    }
    $row = mysql_fetch_assoc($query);
    $id = $row["id"];
    $query = NULL;
    mysql_query("DELETE FROM `Comments` WHERE `accountID` = '$id'");
    mysql_query("DELETE FROM `Likes` WHERE `accountID` = '$id'");
    mysql_query("DELETE FROM `Posts` WHERE `accountID` = '$id'");
    mysql_query("DELETE FROM `Accounts` WHERE `id` = '$id'");
    $arg = mysql_query("SELECT * FROM Following WHERE followingUserID = '$id'");
    if (mysql_num_rows($arg) >= 1) {
        for ($i = 0; $i < mysql_num_rows($arg); $i++) {
            $arr = mysql_fetch_assoc($arg);
            $followingUserID = $arr['followingUserID'];
            $followedUserID = $arr['followedUserID'];
            $art = mysql_fetch_assoc(mysql_query("SELECT `Following Count` FROM Accounts WHERE `id` = '$followedUserID'"));
            $followingCount = $art['Following Count'];
            $followingCount = $followingCount-1;
            $arts = mysql_fetch_assoc(mysql_query("SELECT `Follower Count` FROM Accounts WHERE `id` = '$followingUserID'"));
            $followedCount = $arts['Followed Count'];
            $followedCount = $followedCount-1;
            mysql_query("UPDATE Accounts SET `Following Count` = '$followingCount' WHERE `id` = '$followingUserID'");
            mysql_query("UPDATE Accounts SET `Follower Count` = '$followedCount' WHERE `id` = '$followedUserID'");
            mysql_query("DELETE FROM Following WHERE followingUserID = '$id'");
        }
    }

    exit("Closed");
为什么不干脆做呢

 mysql_query("UPDATE Accounts SET `Following Count` = (`Following Count` - 1) WHERE `id` = '$followingUserID'");

 mysql_query("UPDATE Accounts SET `Follower Count` = (`Following Count` - 1) WHERE `id` = '$followedUserID'");
这样,您就不需要选择这两个选项。

为什么不直接选择呢

 mysql_query("UPDATE Accounts SET `Following Count` = (`Following Count` - 1) WHERE `id` = '$followingUserID'");

 mysql_query("UPDATE Accounts SET `Follower Count` = (`Following Count` - 1) WHERE `id` = '$followedUserID'");

这样你就不需要2个选项了。

像这样使用mysql\u查询:mysql\u查询。。或Dieu错误;你会发现你的错误请告诉我你正在清理你的输入-同时你的代码中存在一个竞争条件;您可以使用SQL将数字列直接递增或递减一个设定的量,这将防止此问题发生。我只是想知道是否有任何明显的错误会阻止我创建新用户,跟踪另一个用户并每次删除该用户,直到其正常工作。您没有正确检查任何查询是否已完成,因此可能会出现其他问题。始终检查查询是否有效。请像这样使用mysql\u查询:mysql\u查询。。或Dieu错误;你会发现你的错误请告诉我你正在清理你的输入-同时你的代码中存在一个竞争条件;您可以使用SQL将数字列直接递增或递减一个设定的量,这将防止此问题发生。我只是想知道是否有任何明显的错误会阻止我创建新用户,跟踪另一个用户并每次删除该用户,直到其正常工作。您没有正确检查任何查询是否已完成,因此可能会出现其他问题。始终检查查询是否正常工作。