2016-02-01 33 views
4

我的HTML:調用一個成員函數的execute()布爾在

<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文件:

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

我的錯誤,當我試圖提交,是:致命錯誤:調用一個成員函數用C執行()上布爾:... \上線18 rent.php

電子郵件,msg_text是VARCHAR類型

+0

只是一個真正的壞錯字。 –

回答

1

你的SQL語句編寫需要更正爲shudent說,但我想你也有叫->execute()(不帶任何參數)之前設置與->bind_param()值。

$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

相關問題