我正在使用 php 来显示我在用户名数据库中的内容。当我想删除用户名时,它可以工作并将其从数据库中删除,但它仍然显示在我的 php 页面中。
这是我正在使用的删除命令:
<table class="table">
<tr><th>#</th><th>Date</th><th>ID</th><th>Actions</th></tr><?php
if ($_GET['a'] == 'delete' && $_GET['i']) {
$UserId = $_GET['i'];
$res=mysql_query("SELECT FROM `users` WHERE `UserId`=$UserId");
$TraderId=mysql_result($res,0,"TraderId");
mysql_query("DELETE FROM `users` WHERE `UserId`=$UserId");
mysql_query("DELETE FROM `traders` WHERE `TraderId`=$TraderId");
echo '<br><br><div class="alert alert-warning"><strong>Bye bye!</strong> Result has been deleted.</div>';
}
if($_GET['s']=="true")
{
echo '<br><br><div class="alert alert-success"><strong>Success!</strong> The user has been saved.</div>';
}
$res = mysql_query("SELECT * FROM `users`");
for ($i = 0; $i < mysql_num_rows($res); $i++) {
$Username = mysql_result($res, $i, "Username");
$UserId = mysql_result($res, $i, "UserId");
$IsAdmin = (string) (bool) mysql_result($res, $i, "IsAdmin");
echo "<tr><td>$UserId</td><td>$Username</td><td>$IsAdmin</td><td>
<a href=\"users.php?a=delete&i=$UserId\" class=\"btn btn-danger\">Delete</a>
<a href=\"user.php?i=$UserId\" class=\"btn btn-primary\">Edit</a></td></tr>";
}
?>
</table>
这是名称应该显示的地方.. 这是显示的交易者页面TraderId
:
<table border="">
<head><tr><th style="padding-bottom:40px; padding-right:70px; padding-top:20px;">Date</th><th style="padding-left:200px; float:right;">Screenshots</th></tr></thead>
<?php
$res=mysql_query("SELECT * FROM `traders`");
for($i=0;$i<mysql_num_rows($res);$i++)
{
$Name=mysql_result($res,$i,"Name");
$Price=mysql_result($res,$i,"Price");
$Timezone=mysql_result($res,$i,"Timezone");
$TraderId=mysql_result($res,$i,"TraderId");
echo '<tbody><tr><td style="padding-left:0px;padding-bottom:10px;">'.$Name.'</td><td style="padding-left:200px;"><a href="details.php?i='.$TraderId.'">View details<a/></td></tr></tbody>';
}
?>
</table>
删除功能再次起作用,因为我看到结果已从我的 sql 数据库中删除,但未从输出页面中删除。