我希望管理员能够根据其用户登录来批准成员。我有一张memebers表,里面有他们所有的信息。假设管理员username= "Mary"
、password="xxxx"
和location="canada"
,那么应该只显示具有其location= "canada"
的成员。这就是我迄今为止所做的。使用此Sql查询,$view_members_query="select * from members";
将显示数据库中的所有成员。我只需要显示管理员根据位置应该看到的内容。请帮帮我。
感谢
管理员登录
<?php
$con = mysqli_connect("localhost","root","","table");
if (mysqli_connect_errno())
{
echo "MySQLi Connection was not established: " . mysqli_connect_error();}
// checking the user
session_start();
if(isset($_POST['login'])){
$location = mysqli_real_escape_string($con,$_POST['location']);
$username = mysqli_real_escape_string($con,$_POST['username']);
$password = mysqli_real_escape_string($con,$_POST['password']);
$sel_user = "select * from Admin_table where location= '$location' AND user_name='$username' AND password='$password'";
$run_user = mysqli_query($con, $sel_user);
if (mysqli_num_rows($run_user)>0)
{
echo "<script>window.open('memberslist.php','_self')</script>";
$_SESSION['user_name']=$_POST['username'];
}
else {
echo "<script>alert('Location, Username or password is not correct, try again!') </script>";
}}
?>
memberslist.php
<table class="simple-table">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Location</th>
</tr>
</thead>
<?php
$view_members_query="select * from members";
$run=mysqli_query($con,$view_members_query);
while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
{
$fname=$row[1];
$lname=$row[2];
$location=$row[3];
?>
<tr>
<!--here showing results in the table -->
<td><?php echo $firstname; ?></td>
<td><?php echo $lastname; ?></td>
<td><?php echo $location; ?></td>
1)在登录代码中,以存储用户名的方式存储用户在会话中的位置。
2) 在memberlist.php中的sql代码中,使用where条件根据位置进行筛选。实际上,代码已经在登录页面的代码中了,因为您使用location来登录用户。只需记住使用会话中的位置即可。