<?php
include "config.php";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = intval($_POST['id']);
    $name = mysqli_real_escape_string($con, $_POST['name']);
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $password = mysqli_real_escape_string($con, $_POST['password']);

    // Hash the password using MD5
    $hashedPassword = md5($password);

    $query = "UPDATE users SET name='$name', email='$email', password='$hashedPassword' WHERE id=$id";
    if (mysqli_query($con, $query)) {
                    echo '<script>window.location.href = "users.php";</script>';
        exit();
    } else {
        echo "Update failed: " . mysqli_error($con);
    }
}
?>