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 ''accounts' WHERE USERNAME = 'test'' at line 1 in .../phplogin/register.php:13 Stack trace: #0 .../phplogin/register.php(13): PDOStatement->execute() #1 {main} thrown in .../phplogin/register.php on line 13
PHP Code of register.php (username, pw and pw2 are defined in the html part):
<?php
if(isset($_POST['submit']))
{require("mysql.php");
$stmt = $mysql->prepare("SELECT * FROM 'accounts' WHERE USERNAME = :user");// Check username
$stmt->bindParam(":user", $_POST['username']);
$stmt->execute();
$count = $stmt->rowCount();
if($count == 0) {
// Username not used
if($_POST['pw'] == $_POST['pw2']) {
// Create User
$stmt = $mysql->prepare("INSERT INTO 'accounts' (USERNAME, PASSWORD) VALUES (:user, :pw)");
$stmt->bindParam(":user", $_POST['username']);
$hash = password_hash($_POST['pw'], PASSWORD_BCRYPT);
$stmt->bindParam(":pw", $hash);
$stmt->execute();
echo "Dein Account wurde angelegt"; // Added account into database
} else {
echo "Passwörter stimmen nicht überein"; // pw and pw2 are not the same
}
} else {
echo "Username bereits vergeben"; // Username used already
}
}
?>
I tried everythink but I can´t find out why it´s not working. If everythink had worked fine it would create a new user with a hashed password in the database. If there were 2 users with the same name it would say that the username is already used.