dor2p0520 2015-04-09 21:32
浏览 34

mysqli没有准备声明的结果?

I have this prepare statement for user login. It works fine, return 1 if login is correct.

After that i need to get user id and his user name (from bd, i think its better then put from input direct to session).

But i have no result in this $rst["id"]; and $rst["user"];

what is the problem?

 $stmt = $mysqli_link->prepare("SELECT id, user FROM cadastro WHERE binary user = ? AND binary senha = ?");
    $stmt->bind_param('ss', $user, $senha);
    $stmt->execute();
    $stmt->store_result();

        $num = $stmt->num_rows;
        if($num > 0)
        {
            //Retorna os dados do banco
            $rst = $stmt->fetch();
                $id     = $rst["id"];
                $user   = $rst["user"];
                $sessionid = md5(time()); 

                echo"$user - $id - $sessionid";
}
?>

thank you!

  • 写回答

1条回答 默认 最新

  • doushishi6513 2015-04-09 21:39
    关注

    You need to use $rst = $stmt->fetch_assoc. $stmt->fetch() is only used after using $stmt->bind_result(), it fetches the results into the variables named in that call.

    Note that using fetch_assoc() with a prepared statement requires that you have the MYSQLND driver installed.

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入