Call to a member function execute() on boolean in

Call to a member function execute() on boolean in

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Call to a member function execute() on boolean in

When you encounter the fatal error Call to a member function execute() on boolean, the root cause is almost always a silent failure occurring earlier in your script's execution path. In PHP, methods like PDOStatement::execute() or mysqli_stmt::execute() return a boolean value: true if the query succeeds, and false if an error occurs. When you chain these calls without checking the result of the previous step, PHP attempts to call execute() on whatever variable holds the result of the preceding line. If that variable is a boolean false, the engine throws the specific error you are seeing.

Looking at the provided code snippet for rent.php, the issue lies in how the prepared statement is initialized and executed. The line $req = $conn->prepare('INSET INTO renter (email, msg_text) VALUES(?, ?)'); contains a critical typo. You have written INSET instead of INSERT. In MySQL, this is not just a syntax error that halts execution immediately; depending on the client library version and specific configuration, it might return a boolean false indicating the prepare failed silently or generated an error that wasn't caught by the standard if (!$result) block used for raw queries.

Even if the typo were corrected to INSERT, there is a second logical flaw in the execution flow. The code attempts to execute the statement immediately after preparation without verifying that the prepare call itself was successful. Modern PHP extensions, particularly PDO and mysqli, require you to check the return value of prepare(). If the SQL syntax is wrong (like INSET) or if the column names email and msg_text do not exist in the renter table, $req will hold a boolean false. The subsequent call $req->execute(...) then crashes because you are trying to invoke a method on that boolean value.

To fix this, you must separate the preparation, the error checking, and the execution into distinct steps. Here is the corrected version of your rent.php file:

<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) {
    die('Connection failed: ' . $conn->connect_error);
}

// Set character set to utf8 explicitly using a prepared statement or query that handles charset
$query = "SET NAMES utf8";
$conn->query($query); // mysqli_connection::query() returns boolean, no need for complex error handling here usually

$sql = "INSERT INTO renter (email, msg_text) VALUES(?, ?)";

// Prepare the statement
$stmt = $conn->prepare($sql);

if (!$stmt) {
    // Check if preparation failed due to syntax errors or missing columns
    die('Prepare failed: ' . htmlspecialchars($conn->error));
}

// Bind parameters and execute
$stmt->bind_param("ss", $_POST['email'], $_POST['msg_text']);

if (!$stmt->execute()) {
    // Execute can also fail if data types don't match or constraints are violated
    die('Execute failed: ' . htmlspecialchars($stmt->error));
}

// Clean up resources
$stmt->close();
$conn->close();

header('Location: menu.php');

There are several important distinctions here regarding the trade-offs between using raw queries and prepared statements. Your original code mixed a raw query() call for setting the character set with a prepared statement for data insertion. While this is generally safe, it introduces unnecessary complexity. If you are using MySQLi, you can often skip the explicit SET NAMES utf8 query if your connection parameters handle the charset correctly in the URL or configuration file, though keeping it is a valid practice for legacy compatibility.

Another subtle pitfall in your original HTML form is the input type. You defined both the email and message fields as <input type="text">. While this works for simple strings, an email field should ideally be type="email". This allows modern browsers to provide better validation and formatting before the data even reaches your PHP script, reducing the likelihood of inserting malformed data into your database. Additionally, the form action uses rent.php but lacks a CSRF token or nonce if this is running in a production environment with sensitive data, though for a simple local prototype, that might be secondary to fixing the fatal error first.

Finally, ensure your database schema matches your SQL intent. The error message indicates these columns are varchar. If you attempt to insert an email address longer than the defined length, or if msg_text contains special characters that conflict with your collation settings without proper escaping (which prepared statements handle automatically), the execute() method will return false. Always inspect the database table structure to ensure the column definitions align with the expected input data types.

Our network