3

I'm doing, or trying to do, a database project for the university, but when registering a user this error appears:

Fatal error: Call to a member function bind_param() on a non-object in (...)

Initially I wrote

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

But then I changed to well, you can see in the code.

<?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();
            }            
        }        
    }
}
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • You've got a syntax error on your prepare line. You need to include a bracket after the last question mark. – bashleigh Feb 07 '15 at 11:53
  • If you're going to trim all your post fields you can do: $_POST = array_map("trim",$_POST); – ReallyMadeMeThink Feb 07 '15 at 12:00
  • Possible duplicate of [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Oct 06 '19 at 16:12

1 Answers1

2

Call to a member function in query's means that the query couldn't get executed because it contains an error.

In this case, you didn't closed the VALUES (). Change $insert = $db->prepare("INSERT INTO customer VALUES (?, ?, ?, ?, ?"); to $insert = $db->prepare("INSERT INTO customer VALUES (?, ?, ?, ?, ?)");

Make sure you do check if an error could get executed. Example of checking if an query could get executed:

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

If this solved your error, I will really appreciate that you vote my answer as answer.

Sombie
  • 38
  • 3