我希望管理员能够根据用户登录信息批准会员。我有一个包含所有信息的成员表。假设管理员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>
答案 0 :(得分:1)
1)在您的登录代码存储中,用户在会话中的位置与存储用户名的方式相同。
2)在memberlist.php的sql代码中,使用where criteria根据位置进行过滤。实际上,代码已经在登录页面的代码中,因为您使用location来登录用户。请记住使用session中的位置。