<?php
ob_clean();
header('Content-Type: application/json; charset=utf-8');
error_reporting(0);

include_once __DIR__ . '/secrets.php';
include 'db_connect.php'; 

$userid         = $_POST['userid'] ?? '';
$address    = $_POST['address'] ?? '';
$name       = $_POST['name'] ?? '';
$key        = $_POST['key'] ?? '';

$security_key = decrypData($key);

if ($security_key === false) {
    echo json_encode(['status'=>'error','message'=>'Invalid encryption data']);
    exit;
}

if ($security_key == SECURITY_KEY_PLAIN) {

    $con = dbConnect();


    // আপডেট কুয়েরি
    $sql = "UPDATE page_table 
            SET name = '$name', 
                address = '$address'
            WHERE userid = '$userid'";

    $result = mysqli_query($con, $sql);

    if ($result) {
        echo json_encode(['status'=>'success','message'=>'Successfully']);
    } else {
        echo json_encode(['status'=>'error','message'=>'Query Error: ' . mysqli_error($con)]);
    }
    
    mysqli_close($con);

} else {
    echo json_encode(['status'=>'error','message'=>'Invalid key or password']);
}
exit;
?>
