如何在php中回显来自mysql当前会话的数据?

时间:2018-01-19 06:37:44

标签: php mysql session

在开始之前,我必须说我是一个非常聪明的菜鸟。我正在线上关于如何使用MySQL创建登录/注册php页面的教程:https://daveismyname.blog/login-and-registration-system-with-php

我将自己的名为'investment'的SQL列添加为int(11)。

我可以回复SESSION用户名,但不能回复会话投资。

投资列的默认值为'0',不确定这是否重要,但无论如何都要说明。

当调用回声时,量应该是的位置就是空的。

index.php(投资回声):

r <- dfp(x,f=nlogf(x))

代码处理SESSION:

<a href="#" class="dropdown-toggle waves-effect waves-button waves-classic fa fa-usd" data-toggle="dropdown"> Invested Amount: $
  <?php echo $_SESSION['investment'];?>
  <i class="fa fa-angle-down">
  </i>
</a>
<ul class="dropdown-menu title-caret dropdown-lg" role="menu">
  <li class="drop-all">
    <a href="#" class="text-center">Portfolio
    </a>
  </li>
  <li class="drop-all">
    <a href="#" class="text-center">Invest
    </a>
  </li>
</ul>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle waves-effect waves-button waves-classic" data-toggle="dropdown">
    <span class="user-name">
      <?php echo htmlspecialchars($_SESSION['username'], ENT_QUOTES); ?>
      <i class="fa fa-angle-down">
      </i>
    </span>
  </a>

1 个答案:

答案 0 :(得分:-1)

这是一个例子。调用当前的ID会话,然后在数据库中选择。你没有必要会话你的所有数据。

$crud = new crud($DB_con);

$id = $_SESSION['id'];

$stmt = $crud->runQuery("SELECT * FROM tbl_login WHERE id=:id");
$stmt->execute(array(":id"=>$id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
echo $userRow['investment'];