Mini Kabibi Habibi

Current Path : C:/xampp/htdocs/clinic/
Upload File :
Current File : C:/xampp/htdocs/clinic/register.php

<?php
session_start();
include 'includes/db.php'; // Ensure the correct path to your db.php file.

$error = "";
$success = "";

// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Get form data
    $functional_division = $_POST['functional_division'];
    $unit_or_section = $_POST['unit_or_section'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $confirm_password = $_POST['confirm_password'];

    // Validate fields
    if (empty($functional_division) || empty($unit_or_section) || empty($username) || empty($password) || empty($confirm_password)) {
        $error = "All fields are required.";
    } elseif ($password !== $confirm_password) {
        $error = "Passwords do not match.";
    } else {
        // Check if the username already exists
        $sql = "SELECT * FROM users WHERE username = :username";
        $stmt = $pdo->prepare($sql);
        $stmt->bindParam(':username', $username);
        $stmt->execute();

        if ($stmt->rowCount() > 0) {
            $error = "Username is already taken.";
        } else {
            // Hash the password
            $hashed_password = password_hash($password, PASSWORD_DEFAULT);

            // Insert new user into the database
            $sql = "INSERT INTO users (functional_division, unit_or_section, username, password) 
                    VALUES (:functional_division, :unit_or_section, :username, :password)";
            $stmt = $pdo->prepare($sql);
            $stmt->bindParam(':functional_division', $functional_division);
            $stmt->bindParam(':unit_or_section', $unit_or_section);
            $stmt->bindParam(':username', $username);
            $stmt->bindParam(':password', $hashed_password);

            if ($stmt->execute()) {
                $success = "Registration successful! You can now <a href='login.php'>login</a>.";
            } else {
                $error = "An error occurred. 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>DCP Inventory - Registration</title>
    <link rel="stylesheet" href="assets/styles.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        /* Slim banner style */
        .banner {
            background-color: #004D40; /* Banner background */
            color: white; /* Text color */
            text-align: center;
            padding: 10px 0; /* Slim padding */
            font-family: Arial, sans-serif;
        }
         .banner p {
            margin: 0; /* Remove margin for compactness */
            font-size: 16px; /* Adjust font size for slim look */
        }

        .banner .large-text {
            font-size: 24px; /* Make main title larger */
            font-weight: bold;
        }

        /* Registration container styling */
        .register-container {
            width: 350px;
            margin: 50px auto;
            padding: 15px; /* Reduced padding to make the container shorter */
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        /* Form styling */
        .register-container input {
            width: 100%;
            padding: 8px; /* Reduced padding on the input fields */
            margin-bottom: 8px; /* Reduced margin between fields */
            border: 1px solid #ccc;
             border-radius: 4px;
        }

        .register-container button {
            width: 100%;
            padding: 8px; /* Reduced padding on the button */
            background-color: #004D40;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        /* Optional: Reduce the size of the form title */
        .register-container h2 {
             font-size: 20px; /* Reduced size for a more compact appearance */
        }

        .register-container button:hover {
            background-color: #003c33;
        }

        .error {
            color: red;
            margin-bottom: 10px;
        }

        .success {
            color: green;
            margin-bottom: 10px;
        }

        .register-container p {
            text-align: center;
        }

        .register-container a {
            color: #004D40;
        }
    </style>
</head>
<body>

    <!-- Banner -->
    <div class="banner">
        <p class="large-text">Schools Division of Batangas City</p>
        <p>Incoming Project</p>
        <p>ICT Unit</p>
    </div>

    <!-- Registration Form -->
    <div class="register-container">
        <h2>Register</h2>

        <!-- Error or Success Message -->
        <?php if ($error): ?>
            <div class="error"><?php echo $error; ?></div>
        <?php endif; ?>
        
        <?php if ($success): ?>
            <div class="success"><?php echo $success; ?></div>
        <?php endif; ?>

        <form action="register.php" method="POST">
            <input type="text" name="functional_division" placeholder="Functional Division" required><br>
            <input type="text" name="unit_or_section" placeholder="Unit or Section" required><br>
            <input type="text" name="username" placeholder="Username" required><br>
            <input type="password" name="password" placeholder="Password" required><br>
            <input type="password" name="confirm_password" placeholder="Confirm Password" required><br>
            <button type="submit">Register</button>
        </form>

        <p>Already have an account? <a href="login.php">Login here</a></p>
    </div>

</body>
</html>