Email : ...">
  

  

  

  
  

  
  



  
  
  

Call member function execute () for boolean in

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 trying to send: Fatal error: calling the execute () member function in boolean in C: ... \ rent.php on line 18

email, msg_text are in varchar format

+7
source share
5 answers

mysqli->preparemay also return FALSE(check http://php.net/manual/en/mysqli.prepare.php ) if an error occurs. Your problem is what you have INSETinstead INSERT.

+14
source

This may help someone: I ran into the same problem. In my case, I missed closing the first prepared statement before executing the second prepared statement.

$select_stmt_type->close(); prepare, .

+5

. , mysql php. , $conn->.

: 1054, : 'xyz' ' '

+2

SQL- , shudent, , ->bind_param() ->execute() ( ).

$stmt = $conn->prepare('INSERT INTO renter (email, msg_text) VALUES(?, ?)');
$stmt->bind_param("ss", $_POST['email'], $_POST['msg_text']);
$stmt->execute();

. PHP: http://php.net/manual/fr/mysqli.prepare.php

0

, -

    $req = $conn->prepare('INSERT INTO renter (email, msg_text) VALUES(?, ?)');
    if(!$req){
       echo "Prepare failed: (". $conn->errno.") ".$conn->error."<br>";
    }

. , , .

0

Source: https://habr.com/ru/post/1626862/


All Articles