34921-vm/register.php
Flatlogic Bot 42d99a2401 1.6
2025-10-14 13:56:45 +00:00

226 lines
6.9 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$error = '';
$success = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = $_POST['password'];
if (empty($username) || empty($email) || empty($password)) {
$error = 'Please fill in all fields.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Invalid email format.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username OR email = :email");
$stmt->execute(['username' => $username, 'email' => $email]);
if ($stmt->fetch()) {
$error = 'Username or email already exists.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$insert_stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (:username, :email, :password)");
$insert_stmt->execute([
'username' => $username,
'email' => $email,
'password' => $hashed_password
]);
header("Location: login.php?registered=true");
exit;
}
} catch (PDOException $e) {
$error = "Database error: " . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - TAP2SKILL</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Lato:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #2A9D8F;
--secondary-color: #E9C46A;
--background-color: #F4F4F4;
--surface-color: #FFFFFF;
--text-color: #264653;
--error-color: #e74c3c;
}
body {
font-family: 'Lato', sans-serif;
margin: 0;
background-color: var(--background-color);
color: var(--text-color);
display: flex;
flex-direction: column;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 24px;
}
header {
background-color: var(--surface-color);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 16px 0;
position: sticky;
top: 0;
z-index: 100;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-family: 'Poppins', sans-serif;
font-size: 24px;
font-weight: 700;
color: var(--primary-color);
text-decoration: none;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
margin-left: 32px;
}
nav ul li a {
text-decoration: none;
color: var(--text-color);
font-weight: 600;
transition: color 0.3s ease;
}
nav ul li a:hover {
color: var(--primary-color);
}
main {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 80px 0;
}
.form-container {
background-color: var(--surface-color);
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
padding: 48px;
width: 100%;
max-width: 480px;
}
.form-title {
font-family: 'Poppins', sans-serif;
font-size: 32px;
text-align: center;
margin-bottom: 32px;
}
form input {
font-family: 'Lato', sans-serif;
padding: 16px;
margin-bottom: 16px;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 16px;
width: 100%;
box-sizing: border-box;
}
form button {
font-family: 'Poppins', sans-serif;
background-color: var(--primary-color);
color: white;
padding: 16px 32px;
border-radius: 8px;
border: none;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
width: 100%;
font-size: 16px;
}
form button:hover {
background-color: #228b80;
}
.error-message {
background-color: var(--error-color);
color: white;
padding: 16px;
border-radius: 8px;
text-align: center;
margin-bottom: 16px;
}
.form-footer {
text-align: center;
margin-top: 24px;
}
.form-footer a {
color: var(--primary-color);
text-decoration: none;
font-weight: 600;
}
footer {
background-color: var(--text-color);
color: white;
text-align: center;
padding: 24px 0;
}
</style>
</head>
<body>
<header>
<nav class="container">
<a href="index.php" class="logo">TAP2SKILL</a>
<ul>
<li><a href="index.php#about">About</a></li>
<li><a href="index.php#features">Features</a></li>
<li><a href="index.php#testimonials">Testimonials</a></li>
<li><a href="index.php#contact">Contact</a></li>
<li><a href="login.php">Login</a></li>
</ul>
</nav>
</header>
<main>
<div class="form-container">
<h2 class="form-title">Create Account</h2>
<?php if ($error): ?>
<div class="error-message"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="register.php" method="post">
<input type="text" name="username" placeholder="Username" required>
<input type="email" name="email" placeholder="Email Address" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Register</button>
</form>
<div class="form-footer">
<p>Already have an account? <a href="login.php">Login here</a>.</p>
</div>
</div>
</main>
<footer>
<div class="container">
<p>&copy; 2025 TAP2SKILL. All Rights Reserved.</p>
</div>
</footer>
</body>
</html>