<?php
$servername = "localhost";
$username = "kaltekgo_admin";
$password = "kaltek@2024";
$database = "kaltekgo_avila";


$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
    die("Erro de conex���o: " . $conn->connect_error);
}

if (isset($_POST['nome'])) {
    $nome = $conn->real_escape_string($_POST['nome']);
    $sql = "SELECT * FROM alunos WHERE nomeAluno LIKE '%$nome%' LIMIT 1";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            echo '
            <tr>
                    <td><input type="hidden" name="aluno_nome" value="' . htmlspecialchars($row["nomeAluno"]) . '">' . htmlspecialchars($row["nomeAluno"]) . '</td>
                    <td>' . htmlspecialchars($row["identificadorTurma"]) . '</td>
                    <td>' . htmlspecialchars($row["nomePai"]) . '</td>
                    <td>' . htmlspecialchars($row["nomeMae"]) . '</td>
                    <td>
                        <div class="radio-container">
                            <label><input type="radio" name="presenca" value="compareceu" required> Compareceu</label>
                            <label><input type="radio" name="presenca" value="nao_compareceu" required> N&atilde;o Compareceu</label>
                        </div>
                    </td>
                    <td><button type="submit" class="botao-salvar">Salvar</button></td>
            </tr>';
        }
    } else {
        echo "<tr><td colspan='6'>Nenhum aluno encontrado</td></tr>";
    }
}

$conn->close();
?>
