2015-02-07 75 views
3

我这样做,或者试图在大学里做,数据库项目,但随后出现注册这个错误用户时:Fatal error: Call to a member function bind_param() on a non-object in (...)mysqli的函数准备查询

Initialy我写

$insert = $db->prepare("INSERT INTO customer (name, email, phonenumber, adress, password) VALUES (?, ?, ?, ?, ?");

但后来我变得很好,你可以在代码中看到。

我搜索了一些答案,但似乎没有任何工作,我很高兴如果有人可以帮助我解决这个问题。

在此先感谢,安德烈

<?php 
require 'db/connect.php'; 
require 'functions/security.php'; 

if(!empty($_POST)) { 

    if(isset($_POST['name'], $_POST['email'], $_POST['address'], $_POST['phone'], $_POST['password'])) { 

     $name = trim($_POST['name']); 
     $email `enter code here` = trim($_POST['email']); 
     $phone = trim($_POST['phone']); 
     $address = trim($_POST['address']); 
     $password = trim($_POST['password']); 

     if(!empty($name) && !empty($email) &&!empty($phone) && !empty($address) &&!empty($password)){ 
       $insert = $db->prepare("INSERT INTO customer VALUES (?, ?, ?, ?, ?"); 
       $insert->bind_param('ssiss', $name, $email, $phone, $address, $password); 
       //$insert->close(); 

      if($insert->execute()){ 
       print_r("Done"); 
       die(); 
      }    
     }   
    } 
} 
?> 
+0

你的准备行上有语法错误。您需要在最后一个问号后加上括号。 – sourRaspberri 2015-02-07 11:53:42

+0

如果你打算修剪所有的后期字段,你可以这样做:$ _POST = array_map(“trim”,$ _ POST); – Abovestand 2015-02-07 12:00:23

回答

2

电话查询的一个成员函数意味着查询没能执行,因为它包含一个错误。

在这种情况下,您没有关闭VALUES()。 更改$insert = $db->prepare("INSERT INTO customer VALUES (?, ?, ?, ?, ?");$insert = $db->prepare("INSERT INTO customer VALUES (?, ?, ?, ?, ?)");

确保您检查是否可以执行错误。检查如果查询可以得到执行的 例子:

$query = $this->_db->prepare("SELECTTEST name FROM user"); //.. Bad query (false) 
if(!$query) //.. If the query is false. 
{ 
    trigger_error('Query couldn\'t get executed'); 
} 

如果这个解决您的错误,我会很感激你投我的答案的答案。