0

Good Day Guys! I want to ask help about this error I already double check the code but the error still exist.

This is the error:

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 ''firstname', 'lastname', 'birthdate','gender','email','phone','street','house...' at line 1 in D:\xampp\htdocs\DentalClinic\Dashboard\pages\databases\userPDO.php:24 Stack trace: #0 D:\xampp\htdocs\DentalClinic\Dashboard\pages\databases\userPDO.php(24): PDOStatement->execute(Array) #1 {main} thrown in D:\xampp\htdocs\DentalClinic\Dashboard\pages\databases\userPDO.php on line 24

See the code

dbconnection.php

<?php
    $serverName = 'localhost';
    $userName = 'root';
    $password = '';
    $dataBase = 'noceabdentalclinic';
    
    try {
        $conn = new PDO('mysql:host=' . $serverName . '; dbname=' . $dataBase, $userName, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
    } catch (PDOException $e) {
        echo 'Error: ' . $e->getMessage();
    }
    
    $pageContext = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

?>

userPDO.php

<?php
include 'dbconnection.php';
session_start();


      if(isset($_POST["create"]))  
      {  
        $firstname   = $_POST['firstname'];
        $lastname    = $_POST['lastname'];
        $birthdate   = $_POST['birthdate'];
        $gender      = $_POST['gender'];
        $email       = $_POST['email'];
        $phone       = $_POST['phone'];
        $username    = $_POST['username'];
        $password    = $_POST['password'];
        $street      = $_POST['street'];
        $housenumber = $_POST['housenumber'];
        $barangay    = $_POST['barangay'];
        $city        = $_POST['city'];
        $roles       = $_POST['roles'];

        $pdoQuery = "INSERT INTO usersprofile ('firstname', 'lastname', 'birthdate','gender','email','phone','street','housenumber','barangay','city','roles') VALUES (:firstname,:lastname,:birthdate,:gender,:email,:phone,:street,:housenumber,:barangay,:city,:roles)";
        $pdoResult = $conn ->prepare($pdoQuery);
        $pdoExec = $pdoResult->execute([":firstname"=>$firstname,":lastname"=>$lastname,":birthdate"=>$birthdate,":gender"=>$gender,":email"=>$email,":phone"=>$phone,":street"=>$street,":housenumber"=>$housenumber,":barangay"=>$barangay,":city"=>$city,":roles"=>$roles]);  // This is the line 24
        
        if($pdoExec)
        {
            echo 'Data Inserted';
        }else{
            echo 'Data Not Inserted';
        }

        
    
      }  
?>

This the the tables in the PhpMyAdmin

enter image description here

Thank you for the help :)

Shadow
  • 33,525
  • 10
  • 51
  • 64
woofMaranon
  • 144
  • 3
  • 15
  • 1
    don't use single quotes for columins names see https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql – nbk Aug 20 '21 at 12:57
  • Thanks guys for your help I already appreciated – woofMaranon Aug 20 '21 at 13:12

1 Answers1

-1
INSERT INTO usersprofile (firstname, lastname, birthdate,gender,email,phone,street,housenumber,barangay,city,roles)

Remove the single quotes from your statement, they are just column names.

pr1nc3
  • 8,108
  • 3
  • 23
  • 36