Select Git revision
register.php
register.php 3.71 KiB
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include 'components/connect.php';
if(isset($_POST['submit'])){
$name = htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8');
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$pass = password_hash($_POST['pass'], PASSWORD_DEFAULT);
$c_pass = $_POST['c_pass']; // ใช้เปรียบเทียบตรง ๆ กับ $_POST['pass']
// ตรวจสอบว่ารหัสผ่านตรงกันหรือไม่
if ($c_pass !== $_POST['pass']) {
$warning_msg[] = 'Confirm password not matched!';
} else {
// อัปโหลดรูปภาพ
$rename = NULL; // ตั้งค่าเริ่มต้นเป็น NULL
if (!empty($_FILES['image']['name'])) {
$image = $_FILES['image']['name'];
$ext = pathinfo($image, PATHINFO_EXTENSION);
$rename = uniqid().'.'.$ext; // ใช้ uniqid() แทน create_unique_id()
$image_size = $_FILES['image']['size'];
$image_tmp_name = $_FILES['image']['tmp_name'];
$image_folder = 'uploaded_files/'.$rename;
if ($image_size > 2000000) {
$warning_msg[] = 'Image size is too large!';
} else {
move_uploaded_file($image_tmp_name, $image_folder);
}
}
// ตรวจสอบว่าอีเมลซ้ำหรือไม่
$verify_email = $conn->prepare("SELECT * FROM `users` WHERE email = ?");
$verify_email->execute([$email]);
if ($verify_email->rowCount() > 0) {
$warning_msg[] = 'Email already taken!';
} else {
// เพิ่มข้อมูลลงฐานข้อมูล
$insert_user = $conn->prepare("INSERT INTO `users`(name, email, password, image) VALUES(?,?,?,?)");
$insert_user->execute([$name, $email, $pass, $rename]);
$success_msg[] = 'Registered successfully!';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>register</title>
<!-- custom css file link -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- header section starts -->
<?php include 'components/header.php'; ?>
<!-- header section ends -->
<section class="account-form">