File manager - Edit - /home/webapp69.cm.in.th/u69319090037/Shop/register.php
Back
<?php /** * Register Page * CMTC Shopping */ require_once __DIR__ . '/config/db.php'; require_once __DIR__ . '/functions/helpers.php'; $database = new Database(); $db = $database->getConnection(); // Load departments for register selection $departments = $db->query("SELECT * FROM departments ORDER BY id ASC")->fetchAll(); $error = ""; $success = ""; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['register'])) { $prefix = trim($_POST['prefix'] ?? ''); $firstname = trim($_POST['firstname'] ?? ''); $lastname = trim($_POST['lastname'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $address = trim($_POST['address'] ?? ''); $email = trim($_POST['email'] ?? ''); $username = trim($_POST['username'] ?? ''); $password = $_POST['password'] ?? ''; $department_id = intval($_POST['department_id'] ?? 0); // Validations if (empty($firstname) || empty($lastname) || empty($email) || empty($username) || empty($password)) { $error = "กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน"; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error = "รูปแบบอีเมลไม่ถูกต้อง"; } else { // Check duplicate $stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE username = ? OR email = ?"); $stmt->execute([$username, $email]); if ($stmt->fetchColumn() > 0) { $error = "ชื่อผู้ใช้งาน หรือ อีเมลนี้ถูกใช้ไปแล้ว"; } else { $avatar_name = null; // Handle Profile Image Upload if (isset($_FILES['avatar']) && $_FILES['avatar']['error'] === UPLOAD_ERR_OK) { $file_tmp = $_FILES['avatar']['tmp_name']; $file_name = $_FILES['avatar']['name']; $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); $allowed = ['jpg', 'jpeg', 'png']; if (in_array($file_ext, $allowed)) { if (!is_dir(__DIR__ . '/uploads')) { mkdir(__DIR__ . '/uploads', 0777, true); } $avatar_name = uniqid('avatar_') . '.' . $file_ext; move_uploaded_file($file_tmp, __DIR__ . '/uploads/' . $avatar_name); } else { $error = "ไฟล์รูปภาพไม่รองรับ (รองรับเฉพาะ JPG, JPEG, PNG)"; } } if (empty($error)) { $hashed_password = password_hash($password, PASSWORD_BCRYPT); // Member Role is 3 $role_id = 3; try { $stmt_ins = $db->prepare(" INSERT INTO users (role_id, department_id, prefix, firstname, lastname, phone, address, email, username, password, avatar, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active') "); $stmt_ins->execute([ $role_id, $department_id ?: null, $prefix, $firstname, $lastname, $phone, $address, $email, $username, $hashed_password, $avatar_name ]); $success = "สมัครสมาชิกสำเร็จเรียบร้อยแล้ว! กรุณาเข้าสู่ระบบ"; } catch (Exception $e) { $error = "เกิดข้อผิดพลาดในการลงทะเบียน: " . $e->getMessage(); } } } } } ?> <!DOCTYPE html> <html lang="th" data-bs-theme="light"> <head> <meta charset="UTF-8"> <title>สมัครสมาชิก - CMTC Shopping</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background-color: #0b0f19; min-height: 100vh; display: flex; align-items: center; justify-content: center; font-family: 'Sarabun', sans-serif; overflow-x: hidden; position: relative; padding: 40px 0; } /* Glowing Abstract Background Orbs */ body::before { content: ""; position: absolute; width: 350px; height: 350px; background: radial-gradient(circle, rgba(13, 110, 253, 0.35) 0%, rgba(13, 110, 253, 0) 70%); top: 10%; left: 10%; border-radius: 50%; z-index: 1; filter: blur(60px); animation: float-slow 15s infinite alternate; } body::after { content: ""; position: absolute; width: 420px; height: 420px; background: radial-gradient(circle, rgba(99, 102, 241, 0.25) 0%, rgba(99, 102, 241, 0) 70%); bottom: 5%; right: 10%; border-radius: 50%; z-index: 1; filter: blur(75px); animation: float-slow 20s infinite alternate-reverse; } @keyframes float-slow { 0% { transform: translateY(0) scale(1) rotate(0deg); } 50% { transform: translateY(-40px) scale(1.1) rotate(180deg); } 100% { transform: translateY(40px) scale(0.9) rotate(360deg); } } .register-card { background: rgba(30, 41, 59, 0.45); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 24px; padding: 45px 40px; width: 100%; max-width: 600px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 40px rgba(13, 110, 253, 0.1); color: #ffffff; z-index: 10; position: relative; } .form-control, .form-select { background: rgba(15, 23, 42, 0.6); border: 1px solid rgba(255, 255, 255, 0.18); color: #fff; border-radius: 10px; padding: 11px 15px; transition: all 0.3s ease; } .form-control::placeholder { color: rgba(255, 255, 255, 0.4) !important; } .form-control:focus, .form-select:focus { background: rgba(15, 23, 42, 0.8); border-color: #0d6efd; color: #fff; box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.25); } .form-select option { background-color: #0f172a; color: #fff; } .form-label { font-weight: 600; letter-spacing: 0.5px; margin-bottom: 8px; color: #cbd5e1; } .btn-primary { background: linear-gradient(135deg, #0d6efd 0%, #4f46e5 100%); border: none; border-radius: 10px; padding: 12px; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4); } .btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(79, 70, 229, 0.6); background: linear-gradient(135deg, #1e40af 0%, #4338ca 100%); } .btn-primary:active { transform: translateY(1px); } </style> </head> <body> <div class="register-card"> <h4 class="text-center mb-4"><i class="bi bi-person-plus text-primary"></i> สมัครสมาชิก</h4> <?php if (!empty($error)): ?> <div class="alert alert-danger py-2 small" role="alert"> <?php echo $error; ?> </div> <?php endif; ?> <?php if (!empty($success)): ?> <div class="alert alert-success py-2 small" role="alert"> <?php echo $success; ?> </div> <div class="text-center"> <a href="login.php" class="btn btn-primary px-4 py-2">เข้าสู่ระบบ</a> </div> <?php else: ?> <form method="POST" enctype="multipart/form-data"> <div class="row"> <div class="col-md-4 mb-3"> <label for="prefix" class="form-label small">คำนำหน้า</label> <select name="prefix" id="prefix" class="form-select"> <option value="นาย">นาย</option> <option value="นาง">นาง</option> <option value="นางสาว">นางสาว</option> </select> </div> <div class="col-md-4 mb-3"> <label for="firstname" class="form-label small">ชื่อจริง *</label> <input type="text" name="firstname" id="firstname" class="form-control" required placeholder="ชื่อ"> </div> <div class="col-md-4 mb-3"> <label for="lastname" class="form-label small">นามสกุล *</label> <input type="text" name="lastname" id="lastname" class="form-control" required placeholder="นามสกุล"> </div> </div> <div class="row"> <div class="col-md-6 mb-3"> <label for="phone" class="form-label small">เบอร์โทรศัพท์</label> <input type="text" name="phone" id="phone" class="form-control" placeholder="เบอร์โทร"> </div> <div class="col-md-6 mb-3"> <label for="email" class="form-label small">อีเมล *</label> <input type="email" name="email" id="email" class="form-control" required placeholder="example@email.com"> </div> </div> <div class="mb-3"> <label class="form-label small">ที่อยู่จัดส่งสินค้า (ระบุล่วงหน้า)</label> <div class="row g-2 mb-2"> <div class="col-md-6"> <select id="reg_region" class="form-select form-select-sm"> <option value="">-- เลือกภาค --</option> </select> </div> <div class="col-md-6"> <select id="reg_province" class="form-select form-select-sm" disabled> <option value="">-- เลือกจังหวัด --</option> </select> </div> <div class="col-md-6"> <select id="reg_district" class="form-select form-select-sm" disabled> <option value="">-- เลือกอำเภอ/เขต --</option> </select> </div> <div class="col-md-6"> <select id="reg_subdistrict" class="form-select form-select-sm" disabled> <option value="">-- เลือกตำบล/แขวง --</option> </select> </div> <div class="col-md-4"> <input type="text" id="reg_zipcode" class="form-control form-control-sm" placeholder="รหัสไปรษณีย์" readonly> </div> <div class="col-md-8"> <input type="text" id="reg_houseno" class="form-control form-control-sm" placeholder="บ้านเลขที่ / ซอย / ถนน"> </div> </div> <textarea name="address" id="reg_address" class="form-control d-none"></textarea> </div> <div class="row"> <div class="col-md-6 mb-3"> <label for="username" class="form-label small">ชื่อผู้ใช้งาน *</label> <input type="text" name="username" id="username" class="form-control" required placeholder="Username"> </div> <div class="col-md-6 mb-3"> <label for="password" class="form-label small">รหัสผ่าน *</label> <input type="password" name="password" id="password" class="form-control" required placeholder="Password"> </div> </div> <div class="mb-4"> <label for="avatar" class="form-label small">รูปภาพโปรไฟล์</label> <input type="file" name="avatar" id="avatar" class="form-control" accept="image/*"> </div> <button type="submit" name="register" class="btn btn-primary w-100 py-2.5 mb-3">สมัครสมาชิก</button> <div class="text-center small"> <span class="text-muted">มีบัญชีผู้ใช้อยู่แล้ว?</span> <a href="login.php" class="text-primary text-decoration-none">เข้าสู่ระบบ</a> </div> </form> <?php endif; ?> </div> <script src="<?php echo base_url('assets/js/thai_address.js'); ?>"></script> <script> document.addEventListener('DOMContentLoaded', function() { initThaiAddressSelector({ region: '#reg_region', province: '#reg_province', district: '#reg_district', subdistrict: '#reg_subdistrict', zipcode: '#reg_zipcode', houseNo: '#reg_houseno', output: '#reg_address' }); }); </script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.26 |
proxy
|
phpinfo
|
Settings