duanaiguang1960 2016-05-11 13:24
浏览 57
已采纳

从数据库中的表中获取一个特定字段并在会话中使用它

I'm currently building a website that has a log in form. Depending on which role this user has a navigation bar has to be displayed accordingly.

For Example : Someone who hasn't yet logged in will have a "login" link. If someone has logged in and is not an admin a different nav bar is displayed.

All log in details are stored in a db and this has to be done using sessions since it will send the user to a different page.

Any ideas ?

Code till now :

$query = "SELECT count(*) FROM tbl_users
            WHERE username = '$username' AND password = '$pass'";

$result = mysqli_query($connection, $query)
        or die("Error in query: ". mysqli_error($connection));

$row = mysqli_fetch_row($result);
$counter = $row[0];

if($counter > 0)
{
    session_start();
    $_SESSION['user']= $username;
    $_SESSION['role'] = $row['role'];
  • 写回答

1条回答 默认 最新

  • duanlu1793 2016-05-11 14:54
    关注

    a somewhat vague question but, check your role.

    if($_SESSION['role']=='admin')
        echo 'I am admin';
    elseif($_SESSION['role']=='customer')
        echo 'I am customer';
    else
        echo 'No valid role / not logged in';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题