gpt4 book ai didi

php - 显示和删除数据库中的数据

转载 作者:行者123 更新时间:2023-11-29 01:21:52 27 4
gpt4 key购买 nike

我是 PHP 的新手,只想制作一个基本页面,我可以在其中查看数据库中的所有用户并删除它们。我已经走了这么远,但它一直告诉我我有一个 undefined index :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();
?>

最佳答案

在 delete_user.php 中你必须得到 user_id

$user_id= $_GET ['id'];

因为在你的<a href="delete_user.php?id= <? echo $rows['user_id']; ?>">delete</a>链接 GET 变量是“id”,而不是“user_id”

关于php - 显示和删除数据库中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19348841/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com