<?php
 session_start();
 require_once('../connect.php');
 require_once('sql_required.php');
 

 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'];
    $account_no = $_POST['account_no'];
    $prev_reading = $_POST['prev_reading'];

    // Update `pres_reading` in `tbl_user_account`
    $updateQuery = "UPDATE tbl_user_account SET pres_reading = '$prev_reading' WHERE unique_id = '$account_no'";
    if (mysqli_query($conn, $updateQuery)) {
        // Proceed to delete the record
        $deleteQuery = "DELETE FROM tbl_members_report WHERE id = '$id'";
        if (mysqli_query($conn, $deleteQuery)) {
            echo 'success';
        } else {
            echo 'error';
        }
    } else {
        echo 'error';
    }
}
?>
