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
Thank you for the help :)