JezK
Edit File: signup.php
<?php require 'config.php'; require 'auth.php'; $error = ''; if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST['username']; $email = $_POST['email']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); try { $stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"); $stmt->execute([$username, $email, $password]); // Login immediately after signup $_SESSION['user_id'] = $pdo->lastInsertId(); $_SESSION['username'] = $username; header("Location: dashboard.php"); exit(); } catch (PDOException $e) { if ($e->getCode() == 23000) { $error = "Username or Email already exists."; } else { $error = "Registration failed. Please try again."; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sign Up - Humare Notes</title> <link rel="stylesheet" href="css/style.css"> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&family=Roboto+Mono&display=swap" rel="stylesheet"> <style> body { display: flex; align-items: center; justify-content: center; min-height: 100vh; } .auth-card { background: var(--card); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; border: 1px solid var(--border); } .auth-title { text-align: center; margin-bottom: 2rem; color: var(--foreground); } .form-group { margin-bottom: 1rem; } .form-group label { display: block; margin-bottom: 0.5rem; color: var(--muted-foreground); } .form-control { width: 100%; padding: 0.75rem; border: 1px solid var(--input); background: var(--background); border-radius: var(--radius); outline: none; color: var(--foreground); font-family: var(--font-sans); } .btn-primary { width: 100%; margin-top: 1rem; } .auth-footer { margin-top: 1rem; text-align: center; font-size: 0.9rem; color: var(--muted-foreground); } .error-msg { color: var(--destructive); margin-bottom: 1rem; text-align: center; } </style> </head> <body> <div class="auth-card"> <h1 class="auth-title">Join Humare Notes</h1> <?php if ($error): ?> <div class="error-msg"><?php echo $error; ?></div> <?php endif; ?> <form method="POST" action=""> <div class="form-group"> <label for="username">Username</label> <input type="text" id="username" name="username" class="form-control" required> </div> <div class="form-group"> <label for="email">Email</label> <input type="email" id="email" name="email" class="form-control" required> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" id="password" name="password" class="form-control" required> </div> <button type="submit" class="btn btn-primary">Sign Up</button> </form> <div class="auth-footer"> Already have an account? <a href="index.php">Log in</a> </div> </div> </body> </html>