在布尔值中调用成员函数execute() [英] Call to a member function execute() on boolean in

查看:58
本文介绍了在布尔值中调用成员函数execute()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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>

我的rent.php文件:

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');

当我尝试提交时,我的错误是:致命错误:在第18行的C:... \ rent.php中,对布尔值的成员函数execute()进行调用

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

电子邮件,msg_text为varchar类型

email, msg_text are in varchar type

推荐答案

mysqli->prepare也可以返回FALSE(请检查

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.

这篇关于在布尔值中调用成员函数execute()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆