bind_param失败但是回显bind_results返回我想要的东西?

时间:2013-01-15 21:30:30

标签: php mysqli

出现错误信息:

  

致命错误:在第22行的/var/www/New/API/Constants.php中调用非对象的成员函数bind_param()

更新了整个constants.php 这是我在constants.php上的代码:

session_start();
if (isset($_SESSION['real_name']))
{
    $username = $_SESSION['real_name'];

    $InnerJoinQuery = $STD->prepare("
    SELECT Users.ID, Users.Password, UserInformation.LastName, UserInformation.Firstname, UserInformation.DOB
    FROM Users
    INNER JOIN UserInformation
    ON Users.ID = UserInformation.UserID WHERE Users.Username = ?");
    $InnerJoinQuery->bind_param("s", $username);
    $InnerJoinQuery->execute();
    $InnerJoinQuery->bind_result($UID, $Password, $LastName, $Firstname, $DOB);
    $InnerJoinQuery->fetch();

    $_SESSION['UID'] = $UID;
    $_SESSION['Password'] = $Password;
    $_SESSION['Firstname'] = $LastName;
    $_SESSION['LastName'] = $Firstname;
    $_SESSION['DOB'] = $DOB;
}

    echo $UID."<br>".$Password."<br>".$LastName."<br>".$Firstname."<br>".$DOB;

但是:

echo $UID."<br>".$Password."<br>".$LastName."<br>".$Firstname."<br>".$DOB;

返回;

  

5   XXX   鳃   达里尔   211094

也:

print_r($_SESSION);
  

数组([real_name] =&gt; InhumaneSlayer [密码] =&gt; xxx [UID] =&gt;   5 [名字] =&gt;吉尔[LastName] =&gt; Daryl [DOB] =&gt; 211094)

以上是预期的输出

预计会有哪些?所以bind_param失败但bind_results正在收集正确的信息?

2 个答案:

答案 0 :(得分:0)

制作本:

    @session_start();
$username = $_SESSION['real_name'];

if (isset($username))
{

到此:

session_start();
if (isset($_SESSION['real_name']))
{
    $username = $_SESSION['real_name'];

............

$InnerJoinQuery->bind_param("s", $username);

您是否检查了会话以确保正在设置此会话。而且我认为你的名字倒数第一名:

$_SESSION['UID'] = $UID;
$_SESSION['Password'] = $Password;
$_SESSION['Firstname'] = $LastName;
$_SESSION['LastName'] = $Firstname;
$_SESSION['DOB'] = $DOB;

尝试回应:

echo $_SESSION['UID']."<br/>" ;
echo $_SESSION['Password']."<br/>" ;
echo $_SESSION['Firstname']."<br/>" ;
echo $_SESSION['LastName'] ."<br/>" ;
echo $_SESSION['DOB'] ."<br/>" ;
echo $_SESSION['real_name']."<br/>" ;

答案 1 :(得分:0)

如果这是您的整页,您如何获得我认为是您的连接变量的$STD

如果您从其他页面包含数据库和此页面.... 包括您的数据库文件。

变化:

session_start();
if (isset($_SESSION['real_name']))
{

要:

include "YourFile";
session_start();
if (isset($_SESSION['real_name']))
{