0

I can't figure out why I keep getting this error: Call to a member function bind_param() on a non-object on line 26

Can someone help me? I don't use PHP often.

<?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();
    }

    ?>
marcos
  • 121
  • 3
  • 14

1 Answers1

-1

First, $mysqli->connect_errno needs to be $mysqli->connect_errno() and $mysqli->connect_error needs to be $mysqli->connect_error().

Then, you should change$mysqli->prepare to:

$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
}
dave
  • 62,300
  • 5
  • 72
  • 93