我是 PHP 新手,只想制作一个基本页面,我可以在其中查看数据库中的所有用户并删除它们。我已经走了这么远,但它一直告诉我我有一个我有和未定义的索引:user_id,虽然它告诉我它已经删除了它没有删除任何内容的字段。这是我的代码:
<?php include_once "includes/scripts.php"; ?>
<?php include_once "includes/connect.php";?>
<?php include_once "includes/cms_page_security.php";?>
<div id="cms_container"><br>
<br>
<h1>MANAGE USERS<img src="images/three_column_grid_line.png" alt="line"></h1>
<p class="logout_btn"><a href="admin_cms.php">Back</a></p>
<?php
$tbl="users"; // Table name
$sql = "SELECT * FROM $tbl";
$result = mysql_query($sql, $connect);
while($rows = mysql_fetch_array($result)){
?>
<?php
echo $rows['user_id'];
echo $rows['user_name'];
echo $rows['user_password'];
?>
<a href="delete_user.php?id= <? echo $rows['user_id']; ?>">delete</a>
<?php
}
?>
<?php
mysql_close();
?>
</div><!--cms_container-->
</body>
</html>
它应该链接到的页面会删除查询:
<?php include_once "includes/connect.php";?>
<?php
$tbl="users";
$user_id= $_GET ['user_id'];
$sql="DELETE FROM $tbl WHERE user_id = '$user_id'";
$result = mysql_query($sql, $connect);
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='delete.php'>Back to main page</a>";
}else {
echo "ERROR";
}
?>
<?php
mysql_close();
?>