我在这里的代码有问题。我不知道为什么。
<h2>Delete Admins</h2><br/>
<?php
$con=mysqli_connect("localhost","root","","poll");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM admin");
echo "<table>
<tr>
<th>ID</th>
<th>Username</th>
<th>Action</th>
</tr>";
?>
<form name="form1" method="POST" action="del-all.php?id=<?php echo $row['admin_id'] ?>" />
<?php
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['admin_id'] . "</td>";
echo "<td>" . $row['login'] . "</td>";
echo "<td><button>DELETE</button></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</form>
这是我发送数据的 del-all.php。我不确定我的错误是在表单中还是在 <button> 中还是在“echo”中,它的动作甚至是它的方法
删除所有.php
<?php
require_once('auth.php');
?>
<?php
$id =$_REQUEST['id'];
$con=mysqli_connect("localhost","root","","poll");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"DELETE FROM admin WHERE admin_id = '$id'");
mysqli_close($con);
?>
<html>
<head>
<title>Successfully Deleted!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../style.css" rel="stylesheet" type="text/css" />
<link href='../fonts/fonts.css' rel='stylesheet' type='text/css'>
<script type="text/JavaScript">
<!--
setTimeout("location.href = 'index.php';",1500);
-->
</script>
</head>
<body>
<fieldset>
<h1 style="color:white;">
Data Deleted Successfully!
</h1>
</fieldset>
</body>
</html>