<?php
// Koneksi ke database
$servername = "localhost";
$database = "u645251767_sipemaaa";
$username = "u645251767_sipemaaa";
$password = "Ramak2@2025";

$conn = new mysqli($servername, $username, $password, $database);

// Cek koneksi
if ($conn->connect_error) {
    die("Koneksi gagal: " . $conn->connect_error);
}

// Data NIM yang ingin dicek
$sheetNIMs = ['123', '124', '125', '999'];

// Siapkan NIM untuk query SQL (amankan dari SQL injection)
$inClause = "'" . implode("','", array_map([$conn, 'real_escape_string'], $sheetNIMs)) . "'";

// Ambil NIM yang ada di database
$sql = "SELECT nim FROM mahasiswas WHERE nim IN ($inClause)";
$result = $conn->query($sql);

$existingNIMs = [];
if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $existingNIMs[] = $row['nim'];
    }
}

// Cek dan tampilkan hasil
echo "<h3>Hasil Pengecekan NIM:</h3><ul>";
foreach ($sheetNIMs as $nim) {
    if (in_array($nim, $existingNIMs)) {
        echo "<li>$nim - <span style='color: green;'>Ada</span></li>";
    } else {
        echo "<li>$nim - <span style='color: red;'>Tidak Ada</span></li>";
    }
}
echo "</ul>";

// Tutup koneksi
$conn->close();
?>
