当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Mysqli function prepare query

问题描述:

I'm doing, or trying to do, a database project for the university but then when registering a user this error appears: Fatal error: Call to a member function bind_param() on a non-object in (...)

Initialy 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.

I searched for some answers but nothing seems to work and I would very glad if someone can help me solving this problem.

Thanks in advance, André

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

}

}

}

}

?>

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: