<?php
include("connection.php");

if (isset($_POST['submit'])) {
    $id=$_POST['id'];
    $user_name = $_POST['user_name'];
    // $password = $_POST['password'];
    $email = $_POST['user_email'];
    $user_type = 'affilate';
    $country = $_POST['country'];
    $city = $_POST['city'];

    // Assuming you have the user's ID stored in a variable named $user_id

    $update_qry = "UPDATE user SET  user_name = '$user_name', user_email = '$email', user_type = '$user_type', country = '$country', city = '$city' WHERE id = '$id'";
    $result = mysqli_query($conn, $update_qry);

    if ($result) {
        header("Location: view_affilate.php?success=Entry Updated Successfully!!!");
    } else {
        header("Location: view_affilate.php?error=Failed update!!!");
    }
} else {
    header("Location: view_affilate.php?error=Something went wrong!!!");
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $itemId = $_POST['item_id'];
    
    if (isset($_POST['activate'])) {
        $status = 1;
    } elseif (isset($_POST['block'])) {
        $status = 0;
    }
    
    $updateQuery = "UPDATE user SET status = $status WHERE id = $itemId";
    mysqli_query($conn, $updateQuery);
    
    // Redirect back to the view table page
    header('Location: view_affilate.php');
    exit();
}
?>
