File manager - Edit - /home/webapp69.cm.in.th/u69319090015/Shop/register.php
Back
<?php require_once 'config.php'; // Redirect if already logged in if (isset($_SESSION['user_id'])) { header("Location: index.php"); exit; } $error = ''; $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $email = trim($_POST['email'] ?? ''); $password = $_POST['password'] ?? ''; $confirm_password = $_POST['confirm_password'] ?? ''; $phone = trim($_POST['phone'] ?? ''); $address = trim($_POST['address'] ?? ''); $role = $_POST['role'] === 'seller' ? 'seller' : 'customer'; if (empty($name) || empty($email) || empty($password)) { $error = "กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน"; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error = "รูปแบบอีเมลไม่ถูกต้อง"; } elseif (strlen($password) < 6) { $error = "รหัสผ่านต้องมีความยาวอย่างน้อย 6 ตัวอักษร"; } elseif ($password !== $confirm_password) { $error = "รหัสผ่านและยืนยันรหัสผ่านไม่ตรงกัน"; } else { // Check duplicate email $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?"); $stmt->execute([$email]); if ($stmt->fetch()) { $error = "อีเมลนี้ถูกใช้งานในระบบแล้ว"; } else { // Hash password & Insert user $hashedPassword = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (name, email, password, phone, address, role) VALUES (?, ?, ?, ?, ?, ?)"); if ($stmt->execute([$name, $email, $hashedPassword, $phone, $address, $role])) { $_SESSION['register_success'] = "สมัครสมาชิกสำเร็จ! กรุณาเข้าสู่ระบบ"; header("Location: login.php"); exit; } else { $error = "เกิดข้อผิดพลาดในการลงทะเบียน กรุณาลองใหม่อีกครั้ง"; } } } } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>สมัครสมาชิก - วิทยาลัยเทคนิคเชียงใหม่ Minimalist Closet</title> <!-- Google Fonts --> <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=Outfit:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap" rel="stylesheet"> <!-- Bootstrap 5 CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <!-- Bootstrap Icons --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.min.css"> <style> :root { --primary-color: #1a1a1a; --accent-color: #8f8270; --bg-color: #faf9f6; --card-bg: #ffffff; --font-display: 'Outfit', 'Sarabun', sans-serif; } body { font-family: var(--font-display); background-color: var(--bg-color); color: var(--primary-color); min-height: 100vh; display: flex; flex-direction: column; } .navbar { background-color: rgba(255, 255, 255, 0.85); backdrop-filter: blur(10px); border-bottom: 1px solid rgba(0, 0, 0, 0.05); } .auth-card { background-color: var(--card-bg); border: none; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.03); padding: 40px; } .btn-dark-custom { background-color: var(--primary-color); color: #ffffff; border: 1px solid var(--primary-color); border-radius: 6px; font-weight: 500; padding: 12px; letter-spacing: 0.5px; transition: all 0.2s ease; } .btn-dark-custom:hover { background-color: var(--accent-color); border-color: var(--accent-color); color: white; } </style> <!-- Custom Theme & Dark Mode CSS --> <link rel="stylesheet" href="assets/css/style.css"> <script src="assets/js/theme-toggle.js"></script> </head> <body> <!-- Header Navbar --> <nav class="navbar navbar-expand-lg sticky-top navbar-light"> <div class="container"> <a class="navbar-brand d-flex align-items-center gap-2" href="index.php"> <img src="assets/images/logo.png" alt="CMTC Logo" style="height: 42px; width: auto;"> <div class="d-flex flex-column" style="line-height: 1.2;"> <span class="fs-6 fw-bold">วิทยาลัยเทคนิคเชียงใหม่</span> <span class="small text-muted" style="font-size: 0.75rem; letter-spacing: 1px;">MINIMALIST CLOSET</span> </div> </a> <div class="ms-auto"> <button type="button" class="theme-toggle-btn" id="themeToggleBtn" title="เปลี่ยนธีม (Light/Dark)"> <i class="bi bi-moon-stars-fill" id="themeIcon"></i> </button> </div> </div> </nav> <!-- Main Content --> <main class="container py-5 my-auto"> <div class="row justify-content-center"> <div class="col-md-8 col-lg-6"> <div class="auth-card"> <h3 class="fw-bold mb-1 text-center">สมัครสมาชิก</h3> <p class="text-muted text-center small mb-4">สร้างบัญชีผู้ใช้ใหม่เพื่อการสั่งซื้อสินค้าที่สะดวกรวดเร็ว</p> <?php if ($error): ?> <div class="alert alert-danger border-0 small py-2.5 mb-4" role="alert"> <i class="bi bi-exclamation-triangle-fill me-2"></i><?= htmlspecialchars($error) ?> </div> <?php endif; ?> <form method="POST" action="register.php"> <div class="mb-3"> <label class="form-label small fw-semibold">ประเภทบัญชี <span class="text-danger">*</span></label> <div class="d-flex gap-4 pt-1"> <div class="form-check"> <input class="form-check-input" type="radio" name="role" id="roleCustomer" value="customer" checked> <label class="form-check-label small" for="roleCustomer"> <i class="bi bi-person me-1"></i>ลูกค้า (ซื้อสินค้า) </label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="role" id="roleSeller" value="seller"> <label class="form-check-label small fw-semibold text-primary" for="roleSeller"> <i class="bi bi-shop me-1"></i>ผู้ขายสินค้า (จัดการสินค้า) </label> </div> </div> </div> <div class="mb-3"> <label class="form-label small fw-semibold">ชื่อ-นามสกุล <span class="text-danger">*</span></label> <input type="text" name="name" class="form-control" placeholder="เช่น สมชาย ใจดี" value="<?= htmlspecialchars($_POST['name'] ?? '') ?>" required> </div> <div class="mb-3"> <label class="form-label small fw-semibold">อีเมล <span class="text-danger">*</span></label> <input type="email" name="email" class="form-control" placeholder="name@example.com" value="<?= htmlspecialchars($_POST['email'] ?? '') ?>" required> </div> <div class="row"> <div class="col-md-6 mb-3"> <label class="form-label small fw-semibold">รหัสผ่าน <span class="text-danger">*</span></label> <input type="password" name="password" class="form-control" placeholder="อย่างน้อย 6 ตัวอักษร" required> </div> <div class="col-md-6 mb-3"> <label class="form-label small fw-semibold">ยืนยันรหัสผ่าน <span class="text-danger">*</span></label> <input type="password" name="confirm_password" class="form-control" placeholder="พิมพ์รหัสผ่านซ้ำอีกครั้ง" required> </div> </div> <div class="mb-3"> <label class="form-label small fw-semibold">เบอร์โทรศัพท์</label> <input type="tel" name="phone" class="form-control" placeholder="08XXXXXXXX" value="<?= htmlspecialchars($_POST['phone'] ?? '') ?>"> </div> <div class="mb-4"> <label class="form-label small fw-semibold">ที่อยู่จัดส่ง</label> <textarea name="address" class="form-control" rows="3" placeholder="บ้านเลขที่, ถนน, ตำบล, อำเภอ, จังหวัด, รหัสไปรษณีย์"><?= htmlspecialchars($_POST['address'] ?? '') ?></textarea> </div> <button type="submit" class="btn btn-dark-custom w-100 mb-3">สมัครสมาชิก</button> <div class="text-center small text-muted"> มีบัญชีผู้ใช้อยู่แล้ว? <a href="login.php" class="fw-bold text-decoration-underline text-body">เข้าสู่ระบบ</a> </div> </form> </div> </div> </div> </main> <!-- Footer --> <footer class="bg-white border-top py-4 text-center mt-auto"> <div class="container"> <p class="mb-1 text-muted">© 2026 วิทยาลัยเทคนิคเชียงใหม่ Minimalist Closet.</p> </div> </footer> <!-- Bootstrap 5 JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings