douhong1703 2014-01-21 01:31
浏览 97
已采纳

使用PHP会话和使用PDO选择bool?

I am trying to do a PHP session that only allows someone who is a Staff member of my CMS to access the administration panel. I am using a bool of, by default, is 0 for a regular member then a 1 for if we are a staff member.

Also, "Fatal error: Call to a member function prepare() on a non-object" is being displayed because the statement is not selecting the information from the database?

$session = ($_SESSION['members']);
$stmt = $db->prepare('SELECT * FROM members WHERE staff = :staff') or trigger_error(mysql_error());
$stmt->execute(array(':staff' == 1));
  while($data = $stmt->fetch()) {
       if($data == 1) {
           include 'styles/headers/header.php';
           include 'styles/content/articles.php';
           include 'styles/footers/footer.php';
           }
       else {
           echo '<meta http-equiv="refresh" content="0; url=../login.php">';
           }
      }

I am not sure how to add the session of them being logged in into the actual select statement of getting the bool for 1 or 0. Maybe I am doing all of this wrong? OR is there an even better way to do this session handling with PHP and PDO?

  • 写回答

1条回答 默认 最新

  • dongzi3805 2014-01-21 01:34
    关注

    You need to create a PDO connection to your database.

    Your problem is not session related. The error message you see is telling you that $db is null.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line