我正在开发一个系统,用户可以注册并登录并查看自己的个人资料,并拥有可以查看和修改用户登录状态的主管理员。 如果管理员更改用户状态,则用户无法登录其帐户。 (阻止用户)。 预定义的用户状态为“Y”,如果admin要限制该用户登录admin,则可以将状态更改为“N”,以便用户无法登录。
我正在学习PHP,我没有得到正确的技术来做到这一点。
下面是我显示用户表的代码,并且想要更改状态。
<table border="1" class="pricing-table-wrapper col-sm-4"> <tr> <th>Id</th> <th>Username</th> <th>Email</th> <th>password</th> <th>first_name</th> <th>last_name</th> <th>city</th> <th>signup_date</th> <th>ac_number</th> <th>bank_name</th> <th>Status</th> <th>Action</th> </tr> <?php //We get the IDs, usernames and emails of users $req = mysqli_query($conn, 'select id, username, email, password, first_name, last_name, city, signup_date, ac_number, bank_name, status from users'); while($dnn = mysqli_fetch_array($req)) { ?> <tr> <td class="left"><?php echo $dnn['id']; ?></td> <td class="left"><?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['first_name'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['last_name'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['city'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['signup_date'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['ac_number'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['bank_name'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['status'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left">CHANGE USER STATUS</td> <?php } ?> </tr> </table>我试过的代码
<td> <a href='changestatus.php?id=<?=$dnn['id']?>'> <img src="a6block.jpg" width="50px" > </a> <?php include('config.php'); if(isset($_GET['id'])) { // lookup the current status of user 'id' // Update DB with the new status $sql_query="SELECT * FROM users WHERE id=".$_GET['id']; $result_set=mysqli_query($conn, $sql_query); $fetched_row=mysqli_fetch_array($result_set); $sql_query = "UPDATE users SET status='N' WHERE id=".$_GET['id']; mysqli_query($conn, $sql_query); } header("Location: users.php"); exit; // redirect back to the previous page ?>?>
这可能是一个错误的技术,我该怎么办?
I am working on a system which user can register and login and see there own profile & have a Main Admin who can see and modify the user login STATUS. If admin change the user status then user can't login to his account. (block User). Predefined user status is "Y" and if admin want to restrict that user to login admin can change the status to "N" so user can't login.
i am learning php and i don't get the right technique to do that.
Below is the code where I show the user table and wan to change the status.
<table border="1" class="pricing-table-wrapper col-sm-4"> <tr> <th>Id</th> <th>Username</th> <th>Email</th> <th>password</th> <th>first_name</th> <th>last_name</th> <th>city</th> <th>signup_date</th> <th>ac_number</th> <th>bank_name</th> <th>Status</th> <th>Action</th> </tr> <?php //We get the IDs, usernames and emails of users $req = mysqli_query($conn, 'select id, username, email, password, first_name, last_name, city, signup_date, ac_number, bank_name, status from users'); while($dnn = mysqli_fetch_array($req)) { ?> <tr> <td class="left"><?php echo $dnn['id']; ?></td> <td class="left"><?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['first_name'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['last_name'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['city'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['signup_date'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['ac_number'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['bank_name'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left"><?php echo htmlentities($dnn['status'], ENT_QUOTES, 'UTF-8'); ?></td> <td class="left">CHANGE USER STATUS</td> <?php } ?> </tr> </table>THE CODE WHICH I TRIED
<td> <a href='changestatus.php?id=<?=$dnn['id']?>'> <img src="a6block.jpg" width="50px" > </a> <?php include('config.php'); if(isset($_GET['id'])) { // lookup the current status of user 'id' // Update DB with the new status $sql_query="SELECT * FROM users WHERE id=".$_GET['id']; $result_set=mysqli_query($conn, $sql_query); $fetched_row=mysqli_fetch_array($result_set); $sql_query = "UPDATE users SET status='N' WHERE id=".$_GET['id']; mysqli_query($conn, $sql_query); } header("Location: users.php"); exit; // redirect back to the previous page ?>?>
THIS IS MAY BE A WRONG TECHNIQUE SO WHAT CAN I DO?
最满意答案
创建指向新PHP页面的链接并传递用户的ID。
<td class="left"> <a href="changestatus.php?id=<?=$dnn['id']?>"> <?php echo htmlentities($dnn['status'], ENT_QUOTES, 'UTF-8'); ?> </a> </td>然后在changestatus.php
if(isset($_GET['id'])){ // lookup the current status of user 'id' // Update DB with the new status } // redirect back to the previous page header("Location: /previouspage.php"); exit;或.. ..为了防止页面重新加载,你总是可以使用AJAX ..
Create a link to a new PHP page and pass the ID of the user..
<td class="left"> <a href="changestatus.php?id=<?=$dnn['id']?>"> <?php echo htmlentities($dnn['status'], ENT_QUOTES, 'UTF-8'); ?> </a> </td>Then in changestatus.php
if(isset($_GET['id'])){ // lookup the current status of user 'id' // Update DB with the new status } // redirect back to the previous page header("Location: /previouspage.php"); exit;Or.. .to prevent a page reload, you could always use AJAX..
更多推荐
发布评论