【问题标题】:How to Access multi Accesslevel in php and mysql [closed]如何在 php 和 mysql 中访问多访问级别 [关闭]
【发布时间】:2015-07-29 05:03:53
【问题描述】:

我正在开发一个简单的 PHP 和 MySQL 大学级别管理系统......所有员工和学生都有自己的帐户......我想展示他们自己的页面
在我的案例中是 3 级管理员,老师,学生 如果学生登录,或管理员登录,教师登录 如何去自己的页面如何?请帮帮我,让我变大... 我的代码是

 if(count($_POST)>0) {
$qr = "SELECT * FROM users WHERE username='" . $_POST["username"] . "' and password = '". $_POST["password"]."' and accessLevel ='".$_POST['role']."'";
    $res = mysql_query($qr) or die($qr);
    if(mysql_num_rows($res) > 0)
    {
        $row = mysql_fetch_array($res);
        $_SESSION['u_id'] = $row['u_id'];
        $_SESSION['username'] = $row['username'];
    //echo $_SESSION['u_id']; die();
    }
        else {
$message = "Invalid Username or Password!";
}
}
if(isset($_SESSION["u_id"])) {
header("Location: admin_home.php");
}
?>
<form class="form-horizontal" action="" method="post">
                        <fieldset>
                            <div class="input-prepend" title="Username" data-rel="tooltip">
                                <span class="add-on"><i class="icon-user"></i></span><input autofocus class="input-large span10" name="username" id="username" type="text" value="admin" />
                            </div>
                            <div class="clearfix"></div>

                            <div class="input-prepend" title="Password" data-rel="tooltip">
                                <span class="add-on"><i class="icon-lock"></i></span><input class="input-large span10" name="password" id="password" type="password" value="admin123456" />
                            </div>
                            <div class="clearfix"></div>
                              <div class="control-group">
                                <label class="control-label" for="selectError3">Plain Select</label>
                                <div class="controls">
                                  <select id="selectError3" name="role" id="role">
                                    <option>Admin</option>
                                    <option>Teacher</option>
                                    <option>Student</option>
                                  </select>
                                </div>
                              </div>
                            <div class="input-prepend">
                            <label class="remember" for="remember"><input type="checkbox" id="remember" />Remember me</label>
                            </div>
                            <div class="clearfix"></div>

                            <p class="center span5">
                            <button type="submit" class="btn btn-primary">Login</button>
                            </p>
                        </fieldset>

                    </form>

【问题讨论】:

  • "help me please im biggnering ... my code is" 是什么意思?
  • 我怀疑它的意思是“我是一个以英语为第二语言的人,没有阅读help center的指南,尤其是关于MCVE的页面,我是初学者在编码。这是我希望你调试的整个程序"

标签: php html mysql


【解决方案1】:

您需要对通过 POST 获得的 role 变量进行 if 测试

如果您发送的 sn-p 如下所示,那么结束:

if(isset($_SESSION["u_id"])) {
 if($_POST['role']=='admin') {
  header("Location: admin_home.php");
 }
 else if($_POST['role']=='teacher') {
  header("Location: teacher_home.php");
 }
 else if($_POST['role']=='student') {
  header("Location: student_home.php");
 }
}

假设您当然已经拥有 student_home.php 和 teacher_home.php 以及 admin_home.php

【讨论】:

  • 试过但没有成功...
  • 数据库中的“角色”列必须填充以下值: 'teacher' 、 'student' 和 'admin' 。要调试,请尝试回显 $_POST['role'] 变量并查看它是否正确接收
  • 注意:未定义索引:第 28 行 C:\xampp\htdocs\Code\index.php 中的角色 注意:未定义索引:C:\xampp\htdocs\Code\index.php 中的角色第 31 行注意:未定义索引:第 34 行 C:\xampp\htdocs\Code\index.php 中的角色
  • 确保 $_POST['role'] 通过回显它的值来正确接收。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-09
  • 1970-01-01
  • 2014-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多