Uko ndani ya app. Fungua kwenye browser kwa muonekano na downloads bora.
May 9, 2026 1 min read

hotel register

Source code
<?php
require 'db.php';

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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $full_name = trim($_POST['full_name'] ?? '');
    $username  = trim($_POST['username'] ?? '');
    $email     = trim($_POST['email'] ?? '');
    $password  = $_POST['password'] ?? '';
    $confirm   = $_POST['confirm'] ?? '';

    /* ================= VALIDATION ================= */

    if (
        $full_name === '' ||
        $username === '' ||
        $email === '' ||
        $password === ''
    ) {

        $error = "⚠️ Tafadhali jaza taarifa zote.";

    } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

        $error = "⚠️ Email si sahihi.";

    } elseif (strlen($password) < 6) {

        $error = "⚠️ Password iwe angalau herufi 6.";

    } elseif ($password !== $confirm) {

        $error = "⚠️ Password hazifanani.";

    } else {

        /* ================= CHECK EXISTING ADMIN ================= */

        $check = $pdo->prepare("
            SELECT id, username, email
            FROM supply_admins
            WHERE username = ? OR email = ?
            LIMIT 1
        ");

        $check->execute([$username, $email]);

        $existingAdmin = $check->fetch(PDO::FETCH_ASSOC);

        if ($existingAdmin) {

            if (
                strtolower($existingAdmin['username']) === strtolower($username)
            ) {

                $error = "⚠️ Username tayari ipo. Tafadhali tumia username nyingine.";

            } elseif (
                strtolower($existingAdmin['email']) === strtolower($email)
            ) {

                $error = "⚠️ Email tayari imesajiliwa.";

            }

        } else {

            /* ================= REGISTER ADMIN ================= */

            $hash = password_hash($password, PASSWORD_DEFAULT);

            $stmt = $pdo->prepare("
                INSERT INTO supply_admins
                (
                    full_name,
                    username,
                    email,
                    password
                )
                VALUES
                (
                    ?,
                    ?,
                    ?,
                    ?
                )
            ");

            $stmt->execute([
                $full_name,
                $username,
                $email,
                $hash
            ]);

            $success = "✅ Admin amesajiliwa kikamilifu. Sasa unaweza ku-login.";
        }
    }
}
?>

<!DOCTYPE html>
<html lang="sw">
<head>

<meta charset="UTF-8">

<title>Admin Register - Supply Manager</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<style>

body{
    min-height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    background:
    linear-gradient(
        135deg,
        #0d6efd,
        #6610f2
    );
    padding:20px;
    font-family:system-ui;
}

.register-card{
    max-width:500px;
    width:100%;
    border:none;
    border-radius:24px;
    overflow:hidden;
    box-shadow:0 20px 45px rgba(0,0,0,.25);
    background:white;
}

.card-header-custom{
    background:
    linear-gradient(
        135deg,
        #0d6efd,
        #4f46e5
    );

    color:white;
    padding:30px;
    text-align:center;
}

.card-header-custom h3{
    font-weight:800;
}

.form-control{
    border-radius:12px;
    padding:13px;
    border:1px solid #d0d5dd;
}

.form-control:focus{
    box-shadow:none;
    border-color:#0d6efd;
}

.btn-primary{
    border-radius:12px;
    padding:13px;
    font-weight:700;
    background:#0d6efd;
    border:none;
}

.btn-primary:hover{
    background:#0b5ed7;
}

a{
    text-decoration:none;
}

.small-text{
    color:#667085;
}

</style>

</head>
<body>

<div class="register-card">

    <div class="card-header-custom">
        <h3>🛡️ Admin Register</h3>
        <p class="mb-0 small">
            Hotel Food Supply Management System
        </p>
    </div>

    <div class="p-4">

        <?php if (!empty($error)): ?>

            <div class="alert alert-danger">
                <?= htmlspecialchars($error) ?>
            </div>

        <?php endif; ?>

        <?php if (!empty($success)): ?>

            <div class="alert alert-success">
                <?= htmlspecialchars($success) ?>
            </div>

        <?php endif; ?>

        <form method="POST" autocomplete="off">

            <div class="mb-3">
                <label class="form-label">
                    Full Name
                </label>

                <input
                    type="text"
                    name="full_name"
                    class="form-control"
                    placeholder="Andika jina kamili"
                    required
                >
            </div>

            <div class="mb-3">
                <label class="form-label">
                    Username
                </label>

                <input
                    type="text"
                    name="username"
                    class="form-control"
                    placeholder="Andika username"
                    required
                >
            </div>

            <div class="mb-3">
                <label class="form-label">
                    Email Address
                </label>

                <input
                    type="email"
                    name="email"
                    class="form-control"
                    placeholder="Andika email"
                    required
                >
            </div>

            <div class="mb-3">
                <label class="form-label">
                    Password
                </label>

                <input
                    type="password"
                    name="password"
                    class="form-control"
                    placeholder="Andika password"
                    required
                >
            </div>

            <div class="mb-3">
                <label class="form-label">
                    Confirm Password
                </label>

                <input
                    type="password"
                    name="confirm"
                    class="form-control"
                    placeholder="Rudia password"
                    required
                >
            </div>

            <button
                type="submit"
                class="btn btn-primary w-100"
            >
                Sajili Admin
            </button>

        </form>

        <div class="text-center mt-4">

            <span class="small-text">
                Tayari una akaunti?
            </span>

            <br>

            <a href="admin_login.php">
                Ingia hapa
            </a>

        </div>

    </div>

</div>

</body>
</html>

🚀 Unahitaji mfumo au website ya biashara?

Chagua huduma hapa chini kisha mteja bofya moja kwa moja kwenda kwenye ukurasa wa huduma au kuwasiliana nasi kwa WhatsApp.

Share this post

Comments

0
No comments yet. Be the first to comment.

Continue Reading

Subscribe

Get new updates

Jiunge upokee posts mpya, tutorials, na updates za mifumo moja kwa moja kwenye email yako.

Quick Actions