diff --git a/html.php b/html.php index 3f6a983..1c27870 100644 --- a/html.php +++ b/html.php @@ -1,3 +1,11 @@ + @@ -12,8 +20,13 @@

Blackjack [21]

+
+
Signed in as:
+ Top Up + Logout +
-
Bank: 1000
+
Bank:
Taruhan: 0
diff --git a/koneksi.php b/koneksi.php index f1df661..7f94225 100644 --- a/koneksi.php +++ b/koneksi.php @@ -9,4 +9,10 @@ $conn = mysqli_connect($host, $user, $pass, $db); if (!$conn) { 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"); +} ?> diff --git a/loginn.php b/loginn.php index 89fcf85..f0ff8c6 100644 --- a/loginn.php +++ b/loginn.php @@ -9,7 +9,12 @@ if(isset($_POST['login'])){ $result = mysqli_query($conn, $sql); 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; } else { $error = 'Invalid username or password.'; diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..3f7b77d --- /dev/null +++ b/logout.php @@ -0,0 +1,7 @@ + diff --git a/register.php b/register.php index 1bc8bcd..6831756 100644 --- a/register.php +++ b/register.php @@ -7,7 +7,12 @@ if (isset($_POST['register'])) { $username = $_POST['username']; $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); if ($result) { diff --git a/topup.php b/topup.php new file mode 100644 index 0000000..8ce1c69 --- /dev/null +++ b/topup.php @@ -0,0 +1,66 @@ + 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.'; + } + } +} +?> + + + + + + + Top Up - OCA GameHub + + + +
+

Top Up Saldo

+

Pengguna:

+

Saldo saat ini:

+ + +
+ + +
+
+ + +
+
+ + +
+
+
+ + diff --git a/users.sql b/users.sql new file mode 100644 index 0000000..f264ffd --- /dev/null +++ b/users.sql @@ -0,0 +1,70 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.1 +-- https://www.phpmyadmin.net/ +-- +-- Host: 127.0.0.1 +-- Generation Time: Dec 01, 2025 at 04:50 AM +-- Server version: 10.4.32-MariaDB +-- PHP Version: 8.0.30 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `login` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `users` +-- + +CREATE TABLE `users` ( + `id` int(11) NOT NULL, + `username` varchar(50) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- +-- Dumping data for table `users` +-- + +INSERT INTO `users` (`id`, `username`, `password`) VALUES +(1, '', ''), +(15, 'Alex', '123'), +(16, 'Ody', '123'), +(17, 'cliff', '123'); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `users` +-- +ALTER TABLE `users` + ADD PRIMARY KEY (`id`), + ADD UNIQUE KEY `username` (`username`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `users` +-- +ALTER TABLE `users` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;