我有一个代码可以获取帐户的ID并将其删除到数据库中 但我需要阻止 ID 1 被删除。
我该怎么做?
<?php
// connect to the database
include('dbconn.php');
// confirm that the 'id' variable has been set
if (isset($_GET['admin_ID']) && is_numeric($_GET['admin_ID']))
{
// get the 'id' variable from the URL
$id = $_GET['admin_ID'];
// delete record from database
if ($stmt = $con->prepare("DELETE FROM tbl_admin WHERE admin_ID = ? LIMIT 1"))
{
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->close();
}
else
{
echo "ERROR: could not prepare SQL statement.";
}
$con->close();
// redirect user after delete is successful
header("Location: DeleteAdmin.php");
}
else
// if the 'id' variable isn't set, redirect the user
{
header("Location: DeleteAdmin.php");
}
?>
答案 0 :(得分:1)
将DELETE FROM tbl_admin WHERE admin_ID = ? LIMIT 1
更改为DELETE FROM tbl_admin WHERE admin_ID = ? AND admin_ID != 1
LIMIT 1
是不必要的,假设您是主要ID,因此永远不会有两个具有相同ID。