这是我的所有PHP代码。
define('DB_SERVER', "mysql.com");
define('DB_USER', "");
define('DB_PASSWORD', "!");
define('DB_DATABASE', "");
$conn = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
$query = "SELECT * FROM `accountsToDo` ORDER BY id LIMIT 1";
$result = $conn->query($query);
while($row = $result->fetch_assoc()) {
$percentageOfMessages =($row["percentageOfMessages"]);
$RemoveDeletedAccounts =($row["RemoveDeletedAccounts"]);
$blacklistUsernames =($row["blacklistUsernames"]);
$userEmail =($row["userEmail"]);
$CUse =($row["CUse"]);
$CPa =($row["CPa"]);
}
$conn->close();
?>
<ul>
<li id="percentageOfMessages"><?php echo $percentageOfMessages; ?></li>
<li id="RemoveDeletedAccounts"><?php echo $RemoveDeletedAccounts; ?></li>
<li id="blacklistUsernames"><?php echo $blacklistUsernames; ?></li>
<li id="userEmail"><?php echo $userEmail; ?></li>
<li id="CUse"><?php echo $CUse; ?></li>
<li id="CPa"><?php echo $CPa; ?></li>
</ul>
我的问题是,在我获得该行的值之后。我想继续删除那一行。
$CUse =($row["CUse"]);
$CPa =($row["CPa"]);
}
$conn = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
$query = "DELETE FROM `accountsToDo` WHERE 1 ORDER BY id LIMIT 1";
$conn->query($query);
$conn->close();
?>
但是当我把它放在那里时,我得到一个错误说......
在null
上调用成员函数close()
如何解决此错误?
答案 0 :(得分:-1)
这应该是:
当你删除某些东西时。确保定义要删除的内容,否则它将删除所有/全部!请参阅下面的调整。
define('DB_SERVER', "mysql.com");
define('DB_USER', "");
define('DB_PASSWORD', "!");
define('DB_DATABASE', "");
$conn = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
$query = "SELECT * FROM `accountsToDo` ORDER BY id LIMIT 1";
$result = $conn->query($query);
$row = $result->fetch_assoc();
?>
<ul>
<li id="percentageOfMessages"><?php echo $row["percentageOfMessages"]; ?></li>
<li id="RemoveDeletedAccounts"><?php echo $row["RemoveDeletedAccounts"]; ?></li>
<li id="blacklistUsernames"><?php echo $row["blacklistUsernames"]; ?></li>
<li id="userEmail"><?php echo $row["userEmail"]; ?></li>
<li id="CUse"><?php echo $row["CUse"]; ?></li>
<li id="CPa"><?php echo $row["CPa"]; ?></li>
</ul>
$query = "DELETE FROM `accountsToDo` WHERE `id` = {$row['id']}";
$conn->query($query);
$conn->close();
?>