<?php
    include('session.php');
    include('dbconn.php');
        
    //error_reporting(E_ALL);
    //ini_set('display_errors', 1);

    date_default_timezone_set('Asia/Kuala_Lumpur');
    $currentDateTime = date('Y-m-d H:i:s');
    
    $id = $_POST['id'] ?? '';
    $name = $_POST['name'] ?? '';
    $age = $_POST['age'] ?? '';
    $nricmykid = $_POST['nricmykid'] ?? '';
    $contact = $_POST['contact'] ?? '';
    $emailadd = $_POST['emailadd'] ?? '';
    $school = $_POST['school'] ?? '';
    $category = $_POST['category'] ?? '';
    $platform = $_POST['platform'] ?? '';
    
    if(empty($id)){
        echo "error";
        exit;
    }

     $stmt = $conn->prepare("UPDATE tblquizict2026 
        SET FullName = ?,
         Age = ?,
         ContactNo = ?,
         SchoolName = ?,
         Category = ?,
         Platform = ?,
         EmailAdd = ?,
         NRICMyKid = ?,
         VerifyDateTime = ?
        WHERE AutoIndex = ?");
    
    if(!$stmt){
        die("Prepare failed: " . $conn->error);
    }

    $stmt->bind_param("sssssssssi", $name, $age, $contact, $school, $category, $platform, $emailadd, $nricmykid, $currentDateTime, $id);
    
   if(!$stmt->execute()){
        echo "error: " . $stmt->error;
    } else {
        if($stmt->affected_rows > 0){
            echo "success";
        } else {
            echo "no change";
        }
    }
    
    $stmt->close();
    $conn->close();

?>
