Delete register.php
This commit is contained in:
parent
fe944b4604
commit
59a3cf7e29
83
register.php
83
register.php
@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
session_start();
|
|
||||||
require 'db.php';
|
|
||||||
|
|
||||||
$err = '';
|
|
||||||
$success = '';
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
$username = trim($_POST['username'] ?? '');
|
|
||||||
$password = $_POST['password'] ?? '';
|
|
||||||
$password2 = $_POST['password2'] ?? '';
|
|
||||||
|
|
||||||
if ($username === '' || $password === '' || $password2 === '') {
|
|
||||||
$err = 'Semua field harus diisi.';
|
|
||||||
} elseif ($password !== $password2) {
|
|
||||||
$err = 'Password tidak cocok.';
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Cek apakah username sudah ada
|
|
||||||
$stmt = $pdo->prepare('SELECT id FROM users WHERE username = ?');
|
|
||||||
$stmt->execute([$username]);
|
|
||||||
|
|
||||||
if ($stmt->fetch()) {
|
|
||||||
$err = 'Username sudah digunakan.';
|
|
||||||
} else {
|
|
||||||
// Insert ke tabel users
|
|
||||||
$hash = password_hash($password, PASSWORD_DEFAULT);
|
|
||||||
$ins = $pdo->prepare('INSERT INTO users (username, password) VALUES (?, ?)');
|
|
||||||
$ins->execute([$username, $hash]);
|
|
||||||
|
|
||||||
// AMBIL user_id baru
|
|
||||||
$user_id = $pdo->lastInsertId();
|
|
||||||
|
|
||||||
// ⬇⬇ TAMBAHKAN users_stats OTOMATIS DI SINI ⬇⬇
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO users_stats (user_id) VALUES (?)");
|
|
||||||
$stmt->execute([$user_id]);
|
|
||||||
// ⬆⬆ TAMBAHAN WAJIB ADA ⬆⬆
|
|
||||||
|
|
||||||
$success = 'Pendaftaran berhasil. Silakan login.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="id">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
||||||
<title>Register - Dam Inggris</title>
|
|
||||||
<link rel="stylesheet" href="assets/css/style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="auth-card">
|
|
||||||
<h1 style="text-align: center;">Daftar</h1>
|
|
||||||
|
|
||||||
<?php if ($err): ?>
|
|
||||||
<div class="error"><?php echo htmlspecialchars($err); ?></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($success): ?>
|
|
||||||
<div class="success"><?php echo htmlspecialchars($success); ?></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<form method="post" action="">
|
|
||||||
<label style="text-align: center;">Username
|
|
||||||
<input name="username" required>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label style="text-align: center;">Password
|
|
||||||
<input type="password" name="password" required>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label style="text-align: center;">Konfirmasi Password
|
|
||||||
<input type="password" name="password2" required>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<button type="submit">Daftar</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<p style="text-align: center;">Sudah punya akun? <a href="index.php">Login</a></p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user