35535-vm/signup.php
Flatlogic Bot 01b406af83 1.1
2025-11-07 05:44:17 +00:00

103 lines
4.2 KiB
PHP

<?php
// Simple, standalone registration page
// No authentication required
require_once 'db/config.php';
$message = '';
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? 'client'; // Default to 'client'
if (empty($name) || empty($email) || empty($password)) {
$message = "Please fill in all fields.";
} else {
// Hash the password for security
$password_hash = password_hash($password, PASSWORD_DEFAULT);
try {
$pdoconn = db();
// Prepare SQL statement to prevent SQL injection
$sql = "INSERT INTO users (name, email, password, role) VALUES (:name, :email, :password, :role)";
$stmt = $pdoconn->prepare($sql);
// Bind parameters
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':password', $password_hash);
$stmt->bindParam(':role', $role);
// Execute the statement
if ($stmt->execute()) {
$message = "Registration successful! You can now log in.";
} else {
$message = "Error: Could not execute the query.";
}
} catch (PDOException $e) {
// Check for duplicate entry
if ($e->errorInfo[1] == 1062) {
$message = "This email address is already registered.";
} else {
$message = "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>Sign Up</title>
<link href="assets/css/bootstrap.min.css?v=<?php echo time(); ?>" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3>Create an Account</h3>
</div>
<div class="card-body">
<?php if (!empty($message)): ?>
<div class="alert alert-info"><?php echo htmlspecialchars($message); ?></div>
<?php endif; ?>
<form action="signup.php" method="post">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role">
<option value="owner">Owner</option>
<option value="client">Client</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Sign Up</button>
</form>
</div>
<div class="card-footer">
<a href="index.php">Back to Home</a>
</div>
</div>
</div>
</div>
</div>
<script src="assets/js/bootstrap.bundle.min.js?v=<?php echo time(); ?>"></script>
</body>
</html>