<?php
session_start();
include 'db.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$id = $_SESSION['user_id'];
$earned = rand(1, 10) / 1000;

$conn->query("UPDATE users SET balance = balance + $earned WHERE id = $id");
$conn->query("INSERT INTO mining_history (user_id, amount) VALUES ($id, $earned)");
header("Location: dashboard.php");
