WEB_PROJECT_TA/register.php

134 lines
3.9 KiB
PHP

<?php
session_start();
require 'config/database.php';
// Buat koneksi database
$database = new Database();
$conn = $database->getConnection();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = trim($_POST['username']);
$password = password_hash(trim($_POST['password']), PASSWORD_DEFAULT);
$role = $_POST['role'];
try {
$stmt = $conn->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, ?)");
$stmt->execute([$username, $password, $role]);
$success = "Pendaftaran berhasil! Silakan login.";
} catch (PDOException $e) {
$error = "Username sudah digunakan atau terjadi kesalahan.";
}
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - FTTH Megadata</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
height: 100vh;
background: url('bg.jpg') no-repeat center center fixed;
background-size: cover;
display: flex;
align-items: center;
justify-content: center;
padding: 15px;
}
.register-container {
background: rgba(255, 255, 255, 0.9);
padding: 40px;
border-radius: 15px;
box-shadow: 0 0 15px rgba(0,0,0,0.2);
text-align: center;
width: 320px;
max-width: 100%;
}
.register-container img {
max-width: 150px;
height: auto;
object-fit: contain;
margin-bottom: 15px;
}
.register-container h2 {
margin-bottom: 20px;
color: #333;
}
.register-container input,
.register-container select {
width: 100%;
padding: 12px;
margin: 8px 0;
border: none;
border-radius: 30px;
background: #f1f1f1;
outline: none;
font-size: 14px;
}
.register-container button {
width: 100%;
padding: 12px;
border: none;
border-radius: 30px;
background: #333;
color: #fff;
font-size: 14px;
cursor: pointer;
}
.register-container button:hover {
background: #555;
}
.register-container p {
font-size: 12px;
margin-top: 15px;
}
.register-container a {
color: #0066cc;
text-decoration: none;
}
.success {
color: green;
margin-bottom: 10px;
}
.error {
color: red;
margin-bottom: 10px;
}
/* Responsif untuk layar kecil */
@media (max-width: 480px) {
.register-container {
padding: 25px;
}
.register-container img {
max-width: 100px;
}
}
</style>
</head>
<body>
<div class="register-container">
<img src="megadata.jpeg" alt="Logo">
<h2>Daftar Akun</h2>
<?php
if (!empty($success)) echo "<p class='success'>$success</p>";
if (!empty($error)) echo "<p class='error'>$error</p>";
?>
<form method="POST">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<select name="role" required>
<option value="">Pilih Role</option>
<option value="engineer">Administrator</option>
<option value="teknisi">Teknisi</option>
</select>
<button type="submit">Daftar</button>
</form>
<p>Sudah punya akun? <a href="login.php">Login di sini</a></p>
</div>
</body>
</html>