首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用sql编辑数据库中的用户

使用sql编辑数据库中的用户
EN

Stack Overflow用户
提问于 2018-06-04 07:30:25
回答 2查看 216关注 0票数 0

我正在尝试生成一个包含所有用户帐户的表,然后让每个用户旁边的按钮来删除或更改用户(admin或非admin)的帐户级别。最好的方法是什么?

下面是我的代码:

代码语言:javascript
复制
<?php
$query = mysql_query("SELECT  user_name,user_id,user_email,user_level
                    FROM users
                    ORDER BY user_name ASC");

echo '<table class="table table-hover">
      <thead class="thead-default">
      <tr>
        <th>Username</th>
        <th>User ID</th>
        <th>Email</th>
        <th>Level</th>
        <th>Options</th>
       </tr>
       </thead>';

while($row = mysql_fetch_array($query)){

  echo '<tbody>
         <tr>
           <td class="col-3">' .$row['user_name'].'</td>
           <td class="col-3">' .$row['user_id'].'</td>
           <td class="col-3">' .$row['user_email'].'</td>
           <td class="col-3">' .$row['user_level'].'</td>  
           <td class="col-3"><a class="btn btn-success" href="#" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span></a>
            <a class="btn btn-success" href="#" data-toggle="tooltip" title="Promote"><span class="glyphicon glyphicon-arrow-up"></span></a>
            <a class="btn btn-danger" href="#"><span class="glyphicon glyphicon-arrow-down" data-toggle="tooltip" title="Demote"></span></a>
            <a class="btn btn-danger" href="delete.php" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span></a>
           </td> 
          </tr>
          </tbody>';
       }
   echo '</table>'; ?>

如有任何帮助,我们将不胜感激:)

编辑:管理员/标准用户通过user_level设置,0为标准用户,1为管理员

编辑2:添加代码

代码语言:javascript
复制
    <?php
include 'connect.php';
include 'header.php';

mysql_query("UPDATE users SET user_level='1' WHERE user_id='".$_GET['user_id']."'");
die("User promoted to admin.");

include 'footer.php';
?>

如果它不走运,我将尝试添加if语句,以反馈数据库行是否发生更改

EN

回答 2

Stack Overflow用户

发布于 2018-06-04 08:32:25

这是代码的例子,因为你的问题缺少一些细节,所以我分享了我的代码。

代码语言:javascript
复制
<table>
<tr>
<th>User Email </th>
<th>Date & Time </th>
<th>Complain Number</th>
<th>Complain Type</th>
<th>Description</th>
<th>Status</th>

</tr>
<?php 
$ccount =1;

$email= $_SESSION["email"];
$query = mysqli_query($con,"Select * from new_complain where new_email = 
'$email'");
while($rows = $query->fetch_assoc())
{
 ?>
<tr>

<input type="hidden" name="<?php echo 'sstd' . $ccount ; ?>" value="<?php 
echo $rows['complain_type']; ?>" placeholder="Student Name" />
<td><?php echo $_SESSION["email"]; ?></td>
<td><?php echo $rows['complain_date']; ?></td>
<td><?php echo $rows['new_id']; ?></td>
<td><?php echo $rows['complain_type']; ?></td>
<td><?php echo $rows['new_complain']; ?></td>
<td><?php echo $rows['comlain_status']; ?></td>

 </tr>

<?php 
  $ccount++;
   } ?>
</table>
票数 0
EN

Stack Overflow用户

发布于 2018-06-04 07:51:16

如果没有完整的细节,它将是这样的:

代码语言:javascript
复制
 <a class="btn btn-success" href="promote.php?id='.$row['user_id'].'" data-toggle="tooltip" title="Promote"><span class="glyphicon glyphicon-arrow-up"></span></a>
 <a class="btn btn-danger" href="demote.php?id='.$row['user_id'].'"><span class="glyphicon glyphicon-arrow-down" data-toggle="tooltip" title="Demote"></span></a>

然后,您需要在与此文件相同的目录中创建一个promote.php,如下所示:

代码语言:javascript
复制
<?php
mysql_query("UPDATE users SET user_level='1' WHERE user_id='".$_GET['user_id']."'");
die("User promoted to admin user.");

和一个类似这样的demote.php

代码语言:javascript
复制
<?php
mysql_query("UPDATE users SET user_level='0' WHERE user_id='".$_GET['user_id']."'");
die("User demoted to standard user.");
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50671898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档