2025-12-01 11:21:23 +07:00

69 lines
2.1 KiB
PHP

<?php
include "koneksi.php";
session_start();
$error = '';
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$user = mysqli_fetch_assoc($result);
$_SESSION['username'] = $user['username'];
// Initialize balance in session (default 1000 if not set)
$_SESSION['balance'] = isset($user['balance']) ? (int)$user['balance'] : 1000;
header("Location: html.php");
exit;
} else {
$error = 'Invalid username or password.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="login.css">
</head>
<body>
<div class="container">
<div class="logo">
<h1>OCAGamingHub</h1>
<p>Welcome back — sign in to continue</p>
</div>
<div class="form-container">
<div class="card-icon">♠</div>
<?php if(!empty($error)): ?>
<div class="error-message show"><?=htmlspecialchars($error)?></div>
<?php endif; ?>
<form action="loginn.php" method="POST">
<div class="form-group">
<label for="username">Username</label>
<input id="username" name="username" type="text" placeholder="Enter username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input id="password" name="password" type="password" placeholder="Enter password" required>
</div>
<div class="button-group">
<button type="submit" name="login" class="btn btn-signin">Sign In</button>
<a href="register.php" class="btn btn-signup">Sign Up</a>
</div>
</form>
</div>
</div>
</body>
</html>