簡體   English   中英

Mysqli函數准備查詢

[英]Mysqli function prepare query

我正在為大學做一個數據庫項目,但是當注冊用戶時出現這個錯誤: Fatal error: Call to a member function bind_param() on a non-object in (...)

我最初寫道

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

在查詢中調用成員函數意味着查詢無法執行,因為它包含錯誤。

在這種情況下,您沒有關閉VALUES()。 更改$insert = $db->prepare("INSERT INTO customer VALUES (?, ?, ?, ?, ?"); to $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');
}

如果這解決了您的錯誤,我將非常感謝您將我的答案作為答案投票。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM