<?php
	session_start();
	if($_SESSION['unohs'] == null){
		header("location:index.php?msg=unauthorized");
	}	
	date_default_timezone_set("Asia/Kolkata");
?>
<?php
include "conn.php";

// Fetch existing records
$sql = "SELECT * FROM tbl_firstdepositreward";
$result = $conn->query($sql);

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    foreach ($_POST['id'] as $key => $id) {
        $rewardAmount = $_POST['rewardAmount'][$key];
        $rechargeAmount = $_POST['rechargeAmount'][$key];
        
        $updateQuery = "UPDATE tbl_firstdepositreward SET rewardAmount = '$rewardAmount', rechargeAmount = '$rechargeAmount' WHERE id = '$id'";
        $conn->query($updateQuery);
    }
    header("Location: update_firstdepositbonus.php?success=1");
    exit();
}
?>
<?php include 'header.php'; ?>

      
      
<div class="main-panel">
    <div class="content-wrapper">
        <div class="row">
            <div class="col-lg-12"> <!-- Full width use karna -->
                <div class="card shadow-sm p-4">
                    <h4 class="font-weight-bold text-dark mb-4">Update Settings</h4>

                    <?php if(isset($_GET['success'])): ?>
                        <div class="alert alert-success text-center">Data updated successfully!</div>
                    <?php endif; ?>

                    <form method="POST">
                        <div class="table-responsive">
                            <table class="table table-striped table-hover text-center align-middle w-100">
                                <thead class="table-primary">
                                    <tr>
                                        <th>ID</th>
                                        <th>Reward Amount</th>
                                        <th>Recharge Amount</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php while ($row = $result->fetch_assoc()): ?>
                                        <tr>
                                            <td>
                                                <input type="hidden" name="id[]" value="<?php echo $row['id']; ?>">
                                                <strong><?php echo $row['id']; ?></strong>
                                            </td>
                                            <td>
                                                <input type="number" name="rewardAmount[]" 
                                                       class="form-control text-center fw-bold border-primary"
                                                       value="<?php echo $row['rewardAmount']; ?>" min="0">
                                            </td>
                                            <td>
                                                <input type="number" name="rechargeAmount[]" 
                                                       class="form-control text-center fw-bold border-success"
                                                       value="<?php echo $row['rechargeAmount']; ?>" min="0">
                                            </td>
                                        </tr>
                                    <?php endwhile; ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="text-center mt-4">
                            <button type="submit" class="btn btn-lg btn-success w-100">Update Data</button>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>




      
</html>

</body>
</html>


