106 lines
4.2 KiB
PHP
106 lines
4.2 KiB
PHP
<?php
|
|
require_once 'db/db.php';
|
|
|
|
$errors = [];
|
|
$success = false;
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$provider_name = trim($_POST['provider_name']);
|
|
$contact_name = trim($_POST['contact_name']);
|
|
$email = trim($_POST['email']);
|
|
$password = $_POST['password'];
|
|
$password_confirm = $_POST['password_confirm'];
|
|
|
|
if (empty($provider_name)) {
|
|
$errors[] = 'Provider name is required.';
|
|
}
|
|
if (empty($contact_name)) {
|
|
$errors[] = 'Contact name is required.';
|
|
}
|
|
if (empty($email)) {
|
|
$errors[] = 'Email is required.';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$errors[] = 'Invalid email format.';
|
|
}
|
|
if (empty($password)) {
|
|
$errors[] = 'Password is required.';
|
|
}
|
|
if ($password !== $password_confirm) {
|
|
$errors[] = 'Passwords do not match.';
|
|
}
|
|
|
|
if (empty($errors)) {
|
|
try {
|
|
$pdo = getDBConnection();
|
|
$sql = "SELECT id FROM providers WHERE email = ?";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$email]);
|
|
if ($stmt->fetch()) {
|
|
$errors[] = 'Email already exists.';
|
|
} else {
|
|
$sql = "INSERT INTO providers (provider_name, contact_name, email, password) VALUES (?, ?, ?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
$stmt->execute([$provider_name, $contact_name, $email, $hashed_password]);
|
|
$success = true;
|
|
}
|
|
} catch (PDOException $e) {
|
|
$errors[] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<?php include 'templates/header.php'; ?>
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
Provider Registration
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="alert alert-danger">
|
|
<ul>
|
|
<?php foreach ($errors as $error): ?>
|
|
<li><?php echo htmlspecialchars($error); ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success">
|
|
Registration successful! Your account is pending approval.
|
|
</div>
|
|
<?php else: ?>
|
|
<form action="register.php" method="post" id="registrationForm">
|
|
<div class="mb-3">
|
|
<label for="provider_name" class="form-label">Provider Name</label>
|
|
<input type="text" class="form-control" id="provider_name" name="provider_name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="contact_name" class="form-label">Contact Name</label>
|
|
<input type="text" class="form-control" id="contact_name" name="contact_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="password_confirm" class="form-label">Confirm Password</label>
|
|
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Register</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'templates/footer.php'; ?>
|