top up fitur
This commit is contained in:
parent
894fd9de19
commit
b3f5aa9b91
15
html.php
15
html.php
@ -1,3 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
// If not logged in, redirect to login
|
||||||
|
if (!isset($_SESSION['username'])) {
|
||||||
|
header('Location: loginn.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="id">
|
<html lang="id">
|
||||||
<head>
|
<head>
|
||||||
@ -12,8 +20,13 @@
|
|||||||
<header>
|
<header>
|
||||||
<h1> Blackjack [21] </h1>
|
<h1> Blackjack [21] </h1>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
<div style="display:flex;gap:12px;align-items:center;margin-bottom:8px;">
|
||||||
|
<div>Signed in as: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></div>
|
||||||
|
<a href="topup.php" style="text-decoration:none;padding:6px 10px;background:#3b82f6;color:#fff;border-radius:6px;">Top Up</a>
|
||||||
|
<a href="logout.php" style="text-decoration:none;padding:6px 10px;background:#ef4444;color:#fff;border-radius:6px;">Logout</a>
|
||||||
|
</div>
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="chip">Bank: <span id="balance">1000</span></div>
|
<div class="chip">Bank: <span id="balance"><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></span></div>
|
||||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bet">
|
<div class="bet">
|
||||||
|
|||||||
@ -9,4 +9,10 @@ $conn = mysqli_connect($host, $user, $pass, $db);
|
|||||||
if (!$conn) {
|
if (!$conn) {
|
||||||
die("Connection failed: " . mysqli_connect_error());
|
die("Connection failed: " . mysqli_connect_error());
|
||||||
}
|
}
|
||||||
|
// Ensure 'balance' column exists in 'users' table. If not, add it with default 0.
|
||||||
|
$check = mysqli_query($conn, "SHOW COLUMNS FROM users LIKE 'balance'");
|
||||||
|
if ($check && mysqli_num_rows($check) == 0) {
|
||||||
|
// Attempt to add the column; ignore errors if table doesn't exist yet.
|
||||||
|
@mysqli_query($conn, "ALTER TABLE users ADD COLUMN balance INT NOT NULL DEFAULT 0");
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -9,7 +9,12 @@ if(isset($_POST['login'])){
|
|||||||
$result = mysqli_query($conn, $sql);
|
$result = mysqli_query($conn, $sql);
|
||||||
|
|
||||||
if (mysqli_num_rows($result) > 0) {
|
if (mysqli_num_rows($result) > 0) {
|
||||||
header("Location: html.php" );
|
$user = mysqli_fetch_assoc($result);
|
||||||
|
session_start();
|
||||||
|
$_SESSION['username'] = $user['username'];
|
||||||
|
// ensure balance key exists
|
||||||
|
$_SESSION['balance'] = isset($user['balance']) ? (int)$user['balance'] : 0;
|
||||||
|
header("Location: html.php");
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
$error = 'Invalid username or password.';
|
$error = 'Invalid username or password.';
|
||||||
|
|||||||
7
logout.php
Normal file
7
logout.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_unset();
|
||||||
|
session_destroy();
|
||||||
|
header('Location: loginn.php');
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@ -7,7 +7,12 @@ if (isset($_POST['register'])) {
|
|||||||
$username = $_POST['username'];
|
$username = $_POST['username'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
$SQL = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
|
// basic escaping to avoid simple injection (keep consistent with existing style)
|
||||||
|
$username = mysqli_real_escape_string($conn, $username);
|
||||||
|
$password = mysqli_real_escape_string($conn, $password);
|
||||||
|
|
||||||
|
// insert with initial balance = 0
|
||||||
|
$SQL = "INSERT INTO users (username, password, balance) VALUES ('$username', '$password', 0)";
|
||||||
$result = mysqli_query($conn, $SQL);
|
$result = mysqli_query($conn, $SQL);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
|||||||
66
topup.php
Normal file
66
topup.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
include 'koneksi.php';
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if (!isset($_SESSION['username'])) {
|
||||||
|
header('Location: loginn.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$amount = isset($_POST['amount']) ? (int)$_POST['amount'] : 0;
|
||||||
|
if ($amount <= 0) {
|
||||||
|
$message = 'Masukkan jumlah top up yang valid (lebih dari 0).';
|
||||||
|
} else {
|
||||||
|
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
||||||
|
// Update balance in DB
|
||||||
|
$update = mysqli_query($conn, "UPDATE users SET balance = balance + $amount WHERE username = '$username'");
|
||||||
|
if ($update) {
|
||||||
|
// Fetch new balance
|
||||||
|
$res = mysqli_query($conn, "SELECT balance FROM users WHERE username = '$username'");
|
||||||
|
if ($res && mysqli_num_rows($res) > 0) {
|
||||||
|
$row = mysqli_fetch_assoc($res);
|
||||||
|
$_SESSION['balance'] = (int)$row['balance'];
|
||||||
|
$message = 'Top up berhasil. Saldo sekarang: ' . $_SESSION['balance'];
|
||||||
|
} else {
|
||||||
|
$message = 'Top up berhasil, tetapi gagal mengambil saldo terbaru.';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = 'Gagal memproses top up. Coba lagi.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="id">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<title>Top Up - OCA GameHub</title>
|
||||||
|
<link rel="stylesheet" href="login.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Top Up Saldo</h2>
|
||||||
|
<p>Pengguna: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></p>
|
||||||
|
<p>Saldo saat ini: <strong><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></strong></p>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="success-message show"><?php echo htmlspecialchars($message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="POST" action="topup.php">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="amount">Jumlah Top Up (angka):</label>
|
||||||
|
<input id="amount" name="amount" type="number" min="1" required />
|
||||||
|
</div>
|
||||||
|
<div class="button-group">
|
||||||
|
<button type="submit" class="btn btn-register">Top Up</button>
|
||||||
|
<a href="html.php" class="btn btn-signin">Kembali</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user