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

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

问题描述

我的html:

 

电子邮件:<input type="text" name="email">消息:<input type="text" name="msg_text"><input type="submit" value="租它"></pre></form>

我的rent.php文件:

connect_error){死($conn->connect_error);}$query = "SET NAMES utf8";$result = $conn->query($query);如果(!$结果){死($conn->错误);}$req = $conn->prepare('INSET INTO renter (email, msg_text) VALUES(?, ?)');$req->execute(array($_POST['email'], $_POST['msg_text']));header('位置:menu.php');

我尝试提交时的错误是:致命错误:调用成员函数 execute() on boolean in C:...\rent.php on line 18

email、msg_text 为 varchar 类型

解决方案

mysqli->prepare 也可以返回FALSE(检查http://php.net/manual/en/mysqli.prepare.php) 如果发生错误.你的问题是你有 INSET 而不是 INSERT.

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

解决方案

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天全站免登陆