Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function execute() on boolean in [duplicate]

Tags:

php

mysql

mysqli

My html :

 <form action="rent.php" method="post"><pre>
        Email : <input  type="text" name="email">
        Message : <input type="text" name="msg_text">
                <input type="submit" value="Rent it">
    </pre></form>

My rent.php file :

<?php
 require_once 'login.php';
   $conn = new mysqli($hn, $un, $pw, $db);
   if ($conn->connect_error) {
    die($conn->connect_error);
}
    $query = "SET NAMES utf8";
    $result = $conn->query($query);
    if (!$result) {
        die($conn->error);
    }

    $req = $conn->prepare('INSET INTO renter (email, msg_text) VALUES(?, ?)');
    $req->execute(array($_POST['email'], $_POST['msg_text']));

    header('Location: menu.php');

My error when I try to submit, is : Fatal error: Call to a member function execute() on boolean in C:...\rent.php on line 18

email, msg_text are in varchar type

like image 867
idkn Avatar asked Feb 01 '16 14:02

idkn


2 Answers

mysqli->prepare can also return FALSE (check http://php.net/manual/en/mysqli.prepare.php) if an error occurred. Your problem is that you have INSET instead of INSERT.

like image 80
tomas.lang Avatar answered Oct 12 '22 14:10

tomas.lang


This may help someone: I was facing same issue. In my case, i have missed to close first prepared statement before executing second prepared statement.

When i have added $select_stmt_type->close(); before executing second prepare statement, it fixed the issue.

like image 40
Dhaval Bhimani Avatar answered Oct 12 '22 12:10

Dhaval Bhimani