I'm trying to make the registration page with PHP, but I'm new to this language and MySQL. So I've been following a tutorial about it. I followed everything correctly and checked multiple times. But I can't see the problem. config.php:
<<?php
$db_user = "root";
$db_pass = "";
$db_name = "useraccounts";
$db = new PDO('mysql:host=localhost;db_name=$db_name', $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
registration.php
<?php
if (isset($_POST['create'])) {
if ($_POST['password'] == $_POST['confirm-password']) {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO users (username, email, password) VALUES(?,?,?)";
$stmtinsert = $db->prepare($sql);
# line 30 \/ \/ \/ \/
$result = $stmtinsert->execute([$username, $email, $password]);
if ($result) {
echo "yeeeet";
} else {
echo "nope";
}
}
} else {
}
?>
Error: Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in C:\xampp\htdocs\Website\registration.php:30 Stack trace: #0 C:\xampp\htdocs\Website\registration.php(30): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\Website\registration.php on line 30