dsaxw4201 2015-04-02 21:17
浏览 121

如何执行2x $ stmt-> execute(); ? 我收到了一个错误

I'm getting an error (so obvious error)

Call to a member function bind_param() on a non-object...

I want to check if user has provided his information when verifying his information. If no, it's a successful echo, but if yes, then I get that error... My php code :

<?php

    if(isset($_POST['configured'])){

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    $username = $_SESSION['username'];

    $stmt = $mysqli->prepare("SELECT gender FROM members WHERE username =  ?");
    $stmt->bind_param('s', $username);
    $stmt->bind_result($gender);
    $stmt->execute();

    while ($stmt->fetch()){
        if(empty($gender)){
            echo "<font color='#DB4D4D'>Verification failed! Please provide your information and try again...</font>";
        } else {
             $_POST['configured'] = 1;
             $sql = "
             UPDATE members
             SET configured = ?
             WHERE username = ?
            ";
            $stmt = $mysqli->prepare($sql);
            $stmt->bind_param('ss', $_POST['configured'], $_SESSION['username']); // This is the error line
            $ok = $stmt->execute();

            if ($ok == TRUE) {
                echo "<p><font color='#00CC00'>Your information has been verified.</font><p>
                      <form action='index.php'> <input type='submit' class='buttondiv' value='Continue to Home Page'>";
            } else {
                echo "Error: " .$stmt->error;
            }
        }
    }
}
?>

Where is problem?

BTW: The error line is not incorrect itself.. there has to be something else going on...

  • 写回答

3条回答 默认 最新

  • douchui4815 2015-04-02 21:30
    关注

    You need to add session_start() to the top of the page. Your bind fails because there is no $_SESSION['username']

    评论

报告相同问题?

悬赏问题

  • ¥15 软件工程用例图的建立(相关搜索:软件工程用例图|画图)
  • ¥15 如何在arcgis中导出拓扑关系表
  • ¥15 处理数据集文本挖掘代码
  • ¥15 matlab2017
  • ¥15 在vxWorks下TCP/IP编程,总是connect()报错,连接服务器失败: errno = 0x41
  • ¥15 AnolisOs7.9如何安装 Qt_5.14.2的运行库
  • ¥20 求:怎么实现qt与pcie通信
  • ¥50 前后端数据顺序不一致问题,如何解决?(相关搜索:数据结构)
  • ¥15 基于蒙特卡罗法的中介效应点估计代码
  • ¥15 罗技G293和UE5.3