Insert class in PHP does not work and shows no error

Asked

Viewed 154 times

0

I got the following code in php:

<?php

class Users extends DB {

    private function verifyUser($email) {
        $select = self::conn()->prepare("SELECT * FROM `users` WHERE email = '{$email}'");
        $select->execute();

        if ($select->rowCount() >= 1) {
            return true;
        } else {
            return false;
        }
    }

    public function insertUser($data = array()) {
        if ($this->verifyUsers($data[2])) {
            return false;
        } else {
            $insert = "INSERT INTO `users` (email) VALUES (?,?,?)";
            $stmt = self::conn()->prepare($insert);

            if ($stmt->execute($data)) {
                return true;
            } else {
                return false;
            }
        }
    }
}

It’s not working, and it also doesn’t show mistakes. Anyone can help?

1 answer

0

Look at your private function verifyUser($email){}

The name of the method you defined is as verifyUser

And in public function insertUser($data = array()){} you are checking a method that does not exist, pay attention, your method is verifyUser you are using verifyUsers with "s". It’ll never work anyway.

Also change: $insert = "INSERT INTOusers(email) VALUES (?,?,?)";

For: $insert = "INSERT INTOusers(email) VALUES (?)";

You don’t need 3 "?"

Note: Use the array [2] in the [0]

  • Puts, hadn’t even paid attention... and why shows no error?

  • $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); You have this in your connection code ?

  • No, I’ll fix it...

  • Try to use too try and catch.

  • It worked... thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.