<?php
include('session.php');
include('dbconn.php');

$emailadd = $_POST['email'];

//$stmt = $conn->prepare("SELECT * FROM tblquizict2026 WHERE EmailAdd = ? LIMIT 1");
$stmt = $conn->prepare("SELECT * FROM tblquizict2026 WHERE EmailAdd = ?");
$stmt->bind_param("s", $emailadd);
$stmt->execute();
$result = $stmt->get_result();

if($result->num_rows > 0){

    $count = 1;

    while($row = $result->fetch_assoc()){

        echo "<div style='border:1px solid #ccc; padding:15px; margin-bottom:15px; border-radius:8px;' id='row_".$row['AutoIndex']."'>";

        echo "<b>".$count++.")</b><br><br>";

        // Name
        echo "Name :<br>
              <input type='text' id='name_".$row['AutoIndex']."' 
              value='".trim($row['FullName'])."' style='width:100%; margin-bottom:10px;' required><br>";

        //AGE
         echo "Age :<br>
              <input type='text' id='age_".$row['AutoIndex']."' 
              value='".trim($row['Age'])."' style='width:100%; margin-bottom:10px;' required><br>";
              
        // NRIC
        echo "MyKid/NRIC :<br>
              <input type='text' id='nricmykid_".$row['AutoIndex']."' 
              value='".$row['NRICMyKid']."' style='width:100%; margin-bottom:10px;' required><br>";

        // Contact No
        echo "Contact No :<br>
              <input type='text' id='contact_".$row['AutoIndex']."' 
              value='".$row['ContactNo']."' style='width:100%; margin-bottom:10px;' required><br>";
        
        //Email
        echo "Email:<br>
              <input type='text' id='email_".$row['AutoIndex']."' 
              value='".strtolower($row['EmailAdd'])."' style='width:100%; margin-bottom:10px;' required><br>";

        //School
        echo "School :<br>
              <input type='text' id='school_".$row['AutoIndex']."' 
              value='".htmlspecialchars($row['SchoolName'])."' style='width:100%; margin-bottom:10px;' required><br>";
              
        //Category
        echo "Category :<br>
            <select id='category_".$row['AutoIndex']."' 
                    style='width:100%; margin-bottom:10px; color:#000;' required>
            
                <option value='CATEGORY 1 : 7 YEAR TO 9 YEARS' ".($row['Category']=='CATEGORY 1 : 7 YEAR TO 9 YEARS'?'selected':'').">
                    CATEGORY 1 : 7 YEAR TO 9 YEARS
                </option>
            
                <option value='CATEGORY 2 : 10 YEARS TO 12 YEARS' ".($row['Category']=='CATEGORY 2 : 10 YEARS TO 12 YEARS'?'selected':'').">
                    CATEGORY 2 : 10 YEARS TO 12 YEARS
                </option>
            
                <option value='CATEGORY 3 : 13 YEARS TO 17 YEARS' ".($row['Category']=='CATEGORY 3 : 13 YEARS TO 17 YEARS'?'selected':'').">
                    CATEGORY 3 : 13 YEARS TO 17 YEARS
                </option>
            
            </select><br>";
              
        echo "Platform :<br>
            <select id='platform_".$row['AutoIndex']."' 
                    style='width:100%; margin-bottom:10px; color:#000;' required>
            
                <option value='LAPTOP' ".($row['Platform']=='LAPTOP'?'selected':'').">
                    LAPTOP
                </option>
            
                <option value='MOBILE PHONE' ".($row['Platform']=='MOBILE PHONE'?'selected':'').">
                    MOBILE PHONE (Highly Recommended)
                </option>
            
                <option value='TABLET' ".($row['Platform']=='TABLET'?'selected':'').">
                    TABLET
                </option>
            
            </select><br>";
              
              
        echo "Competition :<br>
              <input type='text' id='competition".$row['AutoIndex']."' 
              value='".$row['Comp']."' style='width:100%; margin-bottom:10px;' readonly><br>";
          
          
        echo "<button type='button' class='custom-button' 
                    onclick='verifyRow(".$row['AutoIndex'].")'>
                    Verify
                  </button>";
        echo "<br><br>";
        echo "Last Verified on :<br>
              <input type='text' id='competition".$row['AutoIndex']."' 
              value='".date("d-m-Y h:i A", strtotime($row['VerifyDateTime']))."' style='width:100%; margin-bottom:10px;' readonly><br>";
              
        echo "</div>";
    }

} else {
    echo "<p style='color:red;'>No Registration Information Found!</p>";
}
?>