0

I am new to coding. Currently trying to setup registration form. I seached for the answer, as I saw maybe binding parameters before execute() will work. However, I have no idea how to do it. Please help. The code below shows following error:

Fatal error: Uncaught Error: Call to a member function execute() on boolean in C:\xampp\htdocs\kibble\php-user-registration-form\DataSource.php:99 Stack trace: #0 C:\xampp\htdocs\kibble\php-user-registration-form\Member.php(83): Phppot\DataSource->insert('INSERT INTO reg...', 'ssss', Array) #1 C:\xampp\htdocs\kibble\php-user-registration-form\index.php(20): Phppot\Member->insertMemberRecord('lalafasdf123', 'Moka24', '123123123123', 'localoca@gmail....') #2 {main} thrown in C:\xampp\htdocs\kibble\php-user-registration-form\DataSource.php on line 99

    public function insert($query, $paramType, $paramArray)
    {
        print $query;
        $stmt = $this->conn->prepare($query);
        $this->bindQueryParams($stmt, $paramType, $paramArray);
        $stmt->execute();
        $insertId = $stmt->insert_id;
        return $insertId;
    }

insert function if needed

    function insertMemberRecord($username, $displayName, $password, $email)
    {
        $passwordHash = md5($password);
        $query = "INSERT INTO registered_users (user_name, display_name, password, email) VALUES (?, ?, ?, ?)";
        $paramType = "ssss";
        $paramArray = array(
            $username,
            $displayName,
            $passwordHash,
            $email
        );
        $insertId = $this->ds->insert($query, $paramType, $paramArray);
        return $insertId;
    }
  • 1
    If you aren't doing explicit error checking you need to configure mysqli to do it for you, e.g. `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`. – Álvaro González May 23 '20 at 15:39
  • ok, but where I can paste it? – Kibble Shop May 23 '20 at 15:44
  • What do you mean? In your PHP script. Before errors can happen. – Álvaro González May 23 '20 at 15:47
  • Sry, thanks for your answer. I have added it before $stmt->execute(); There is now one more line: INSERT INTO registered_users (user_name, display_name, password, email) VALUES (?, ?, ?, ?) Does it mean something? – Kibble Shop May 23 '20 at 15:52
  • 1
    You've enabled error reporting *after* the error. Why don't you just make `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` the first line in your script? – Álvaro González May 23 '20 at 15:54
  • omg, thanks a lot. I have added this line as the first and saw an error: unknown column "display_name", so I just append this column and it is working now. Thanks again) – Kibble Shop May 23 '20 at 16:02

1 Answers1

0

I have added the line mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); as the first and saw an error: unknown column "display_name", so I just append this column and it is working now