aulinha
This commit is contained in:
167
aula15.php
Normal file
167
aula15.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Atividade texto</title>
|
||||
|
||||
<style>
|
||||
.f2{
|
||||
position: fixed;
|
||||
top:20%;
|
||||
left:20%;
|
||||
}
|
||||
|
||||
.f3{
|
||||
position: fixed;
|
||||
top:20%;
|
||||
left:50%;
|
||||
}
|
||||
|
||||
.verd {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Atividade texto</h1>
|
||||
|
||||
<div class="f2">
|
||||
<h2>Cadastro</h2>
|
||||
<form action="aula15.php" method="POST">
|
||||
<table>
|
||||
<tr><td>Nome:</td><td><input type="text" name="nome"></td></tr>
|
||||
<tr><td>Telefone:</td><td><input type="text" name="tel"></td></tr>
|
||||
<tr><td>Documento:</td><td><input type="text" name="doc"></td></tr>
|
||||
<tr><td>Curso:</td><td>
|
||||
<select name="curso">
|
||||
<option value="escolha">Escolha um curso</option>
|
||||
<option value="Administração">Administração</option>
|
||||
<option value="Mecânica">Mecânica</option>
|
||||
<option value="Informatica">Informatica</option>
|
||||
<option value="Enfermagem">Enfermagem</option>
|
||||
</select>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td><input type="reset" value="Apagar"></td>
|
||||
<td><input type="submit" value="Cadastrar" name="cadastrar"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="f3">
|
||||
<h2>Consulta</h2>
|
||||
<form action="aula15.php" method="POST">
|
||||
<table>
|
||||
<tr><td>Inscrição:</td><td><input type="text" name="inscricao"></td></tr>
|
||||
<tr><td>Nome:</td><td><input type="text" name="nome_consulta"></td></tr>
|
||||
<tr><td>Curso:</td><td>
|
||||
<select name="curso_consulta">
|
||||
<option value="escolha">Escolha um curso</option>
|
||||
<option value="Administração">Administração</option>
|
||||
<option value="Mecânica">Mecânica</option>
|
||||
<option value="Informatica">Informatica</option>
|
||||
<option value="Enfermagem">Enfermagem</option>
|
||||
</select>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td><input type="reset" value="Apagar"></td>
|
||||
<td><input type="submit" value="Consultar" name="consultar"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<br><hr><br>
|
||||
|
||||
<?php
|
||||
|
||||
if (isset($_POST['cadastrar'])) {
|
||||
$nome = isset($_POST['nome']) ? trim($_POST['nome']) : '';
|
||||
$tel = isset($_POST['tel']) ? trim($_POST['tel']) : '';
|
||||
$doc = isset($_POST['doc']) ? trim($_POST['doc']) : '';
|
||||
$curso = isset($_POST['curso']) ? $_POST['curso'] : '';
|
||||
|
||||
if (!empty($nome) && !empty($tel) && !empty($doc) && $curso != 'escolha') {
|
||||
$arquivo = "inscricoes.txt";
|
||||
$inscricao_num = 1;
|
||||
|
||||
if (file_exists($arquivo)) {
|
||||
$contents = file_get_contents($arquivo);
|
||||
$linhas = explode("\n", trim($contents));
|
||||
$inscricao_num = count(array_filter($linhas)) + 1;
|
||||
}
|
||||
|
||||
$dados = "$inscricao_num|$nome|$tel|$doc|$curso\n";
|
||||
file_put_contents($arquivo, $dados, FILE_APPEND | LOCK_EX);
|
||||
|
||||
echo "<p class='verd'>Inscrição n° $inscricao_num realizada com sucesso!<br>";
|
||||
echo "Nome: $nome<br>";
|
||||
echo "Telefone: $tel<br>";
|
||||
echo "Documento: $doc<br>";
|
||||
echo "Curso: $curso</p>";
|
||||
} else {
|
||||
echo "<p style='color: red;'>Por favor, preencha todos os campos e selecione um curso.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['consultar'])) {
|
||||
$inscricao = isset($_POST['inscricao']) ? trim($_POST['inscricao']) : '';
|
||||
$nome_consulta = isset($_POST['nome_consulta']) ? trim($_POST['nome_consulta']) : '';
|
||||
$curso_consulta = isset($_POST['curso_consulta']) ? $_POST['curso_consulta'] : '';
|
||||
|
||||
$arquivo = "inscricoes.txt";
|
||||
|
||||
if (file_exists($arquivo)) {
|
||||
$contents = file_get_contents($arquivo);
|
||||
$linhas = explode("\n", trim($contents));
|
||||
$encontrou = false;
|
||||
|
||||
echo "<h3>Resultados da Consulta:</h3>";
|
||||
|
||||
foreach ($linhas as $linha) {
|
||||
if (empty($linha)) continue;
|
||||
|
||||
list($num, $nome_arq, $tel_arq, $doc_arq, $curso_arq) = explode("|", $linha);
|
||||
|
||||
$match = true;
|
||||
|
||||
if (!empty($inscricao) && $num != $inscricao) {
|
||||
$match = false;
|
||||
}
|
||||
|
||||
if (!empty($nome_consulta) && stripos($nome_arq, $nome_consulta) === false) {
|
||||
$match = false;
|
||||
}
|
||||
|
||||
if ($curso_consulta != 'escolha' && $curso_arq != $curso_consulta) {
|
||||
$match = false;
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
echo "<p class='verd'>";
|
||||
echo "Inscrição: $num<br>";
|
||||
echo "Nome: $nome_arq<br>";
|
||||
echo "Telefone: $tel_arq<br>";
|
||||
echo "Documento: $doc_arq<br>";
|
||||
echo "Curso: $curso_arq";
|
||||
echo "</p><hr>";
|
||||
$encontrou = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$encontrou) {
|
||||
echo "<p style='color: red;'>Nenhuma inscrição encontrada com os critérios informados.</p>";
|
||||
}
|
||||
} else {
|
||||
echo "<p style='color: red;'>Nenhuma inscrição cadastrada ainda.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user