在第26行的非对象上调用成员函数bind_param()

时间:2017-04-19 17:35:51

标签: php

我无法弄清楚为什么我一直收到此错误:在第26行的非对象上调用成员函数bind_param()

有人能帮助我吗?我经常不使用PHP。

<?php

    $guests = $_POST['guests'];
    $organizations = $_POST['organizations'];
    $email = $_POST['email'];
    $team = $_POST['team'];

    if (trim($email) == "") {
      include("blank_email.php");
      exit(0);
    }

    $mysqli = new mysqli("localhost", "username", "******", "signin_database");

    function error_page($title, $description, $errmsg) {
        include("error.php");
    }        

    function thankyou($email) {
        include("thankyou.php");
    }

    if ($mysqli->connect_errno) {
        error_page("Cannot Connect", "Cannot connect to database", $mysqli->connect_error);
        }
    else {
        $stmt = $mysqli->prepare("INSERT INTO user_input (guests, organizations, email, team, timestamp) VALUES (?, ?, ?, ?, NOW());");
        $stmt->bind_param("isss", $guests, $organizations, $email, $team);
        if (!$stmt->execute()) {
            error_page("Could not Add", "Could not add email and comment", $stmt->error);
        }
        else {
            thankyou($email);
        }
        $stmt->close();           
        $mysqli->close();
    }

    ?>

1 个答案:

答案 0 :(得分:-1)

首先,$mysqli->connect_errno必须为$mysqli->connect_errno()$mysqli->connect_error必须为$mysqli->connect_error()

然后,您应该将$mysqli->prepare更改为:

$stmt =  $mysqli->stmt_init();
if ($stmt->prepare("INSERT INTO user_input (guests, organizations, email, team, timestamp) VALUES (?, ?, ?, ?, NOW())")) {
  //bind param, execute, etc.
} else {
    //handle the error
}