prepare($sql); $stmt->execute([$email]); if ($stmt->fetch()) { die('Email already exists.'); } $password_hash = password_hash($password, PASSWORD_BCRYPT); $sql = "INSERT INTO users (name, email, password) VALUES (?, ?, ?)"; $stmt = $pdo->prepare($sql); if ($stmt->execute([$name, $email, $password_hash])) { $user_id = $pdo->lastInsertId(); $_SESSION['user_id'] = $user_id; $_SESSION['user_name'] = $name; header("Location: index.php"); exit; } else { die("Error: Could not execute the query."); } } catch (PDOException $e) { die("Could not connect to the database $dbname :" . $e->getMessage()); } } ?>