0

I'm having this error and I can't figure out why.

I have a form to add a user, and in the controller, I want to check if the email entered in the form doesn't already exist. But it throws me this error and I frankly don't understand the reason.

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''userlogin' WHERE 'email' = 'nba@gmail.com'' at line 1 in C:\xampp\htdocs\test\controllers\adduser.php:14 Stack trace: #0 C:\xampp\htdocs\test\controllers\adduser.php(14): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\test\controllers\adduser.php on line 14

my code is :

    {
        $emailsearch = $_POST['email'];

        $query = $DBH->prepare("SELECT 'email' FROM 'userlogin' WHERE 'email' = ?");
        $query->bindValue(1,$emailsearch);
        $query->execute();
        if($query->rowCount() > 0)
        {
            header('location:../views/adduser.php?status=danger&message='.urlencode('Adresse email existe déjà'));
        }else{
            $email = $_POST['email'];
        }
        
    } ```


Can someone tell me why please ? I really don't understand, my SQL syntax seems correct to me..

[![Here is my database :][1]][1]


  [1]: https://i.stack.imgur.com/1EgyZ.png
YesItsMe
  • 13
  • 6
  • Do not single quote identifiers! See the duplicate. – sticky bit Apr 24 '21 at 18:23
  • And **never** post images of tables. Use the `CREATE` and `INSERT` statements needed to create and fill them as **text**, **no** screenshots nor other images. – sticky bit Apr 24 '21 at 18:24
  • @stickybit thank you, yeah it was the '' instead of the ``. – YesItsMe Apr 24 '21 at 18:27
  • @stickybit I'm afraid I didn't totally understand your last advice, is it beacause of confidentiality or am I doing something wrong with my query ? It's a school project, nothing is online. – YesItsMe Apr 24 '21 at 18:29
  • No, it is not about confidentiality. An image of a table (or also any code) isn't easily consumable by anyone who wants to help you and create a test environment on their site therefore. They'd be forced to translate (or transliterate if you will) the image to code (DDL and DML for tables) that would create such an environment. But that's actually not their job. It's your job when asking to provide anything that makes it easy to help you. So you should post the DDL and DML of tables and not an images. The latter make it harder to help you and therefore less likely that you get help. – sticky bit Apr 24 '21 at 18:35
  • @stickybit okay my bad, next time i'll do it this way – YesItsMe Apr 24 '21 at 19:26

0 Answers0