CadAniversariantes

Download do Código
read.php (Apenas Leitura)
<?php
	$tabela = '';
	$pessoas = mysqli_query($conn, "SELECT * FROM pessoas ORDER BY id DESC");
	if ($pessoas && mysqli_num_rows($pessoas) > 0) { 
		while($row = mysqli_fetch_assoc($pessoas)) {
			$tabela .= 
				'<tr>' .
					'<td>'. $row['id']. '</td>' .
					'<td>'. $row['nome'] . '</td>' .
					'<td>'. date('d/m/Y', strtotime($row['data_nascimento'])) . '</td>' .
					'<td>' .
						'<a href="index.php?bEditar='. $row['id'] .'" class="btn btn-edit">Editar</a>' .
						'<a href="index.php?bExcluir='. $row['id'] .'" class="btn btn-del" onclick="return confirm(\'Tem certeza que deseja excluir?\')">Excluir</a>' .
					'</td>' .
				'</tr>';
		}
	} else {
		$tabela .= 
			'<tr>' .
				'<td colspan="4">Nenhum registro encontrado.</td>' .
			'</tr>';
	}
?>
update.php (Apenas Leitura)
<?php
	if (isset($_GET['bAtualizar'])) {
		$id   = $_GET['bAtualizar'];
		$nome = $_GET['nome'];
		$data_nascimento = $_GET['data_nascimento'];
		if ($id > 0 && !empty($nome) && !empty($data_nascimento)) {
			$sql = "UPDATE pessoas SET nome = '$nome', data_nascimento = '$data_nascimento' WHERE id = $id";
			mysqli_query($conn, $sql);
		}
	}
?>
index.php (Apenas Leitura)
<?php
	$id  =0;
	if (isset($_GET['editar']))  $id=$_GET['editar'];
	if (isset($_GET['excluir'])) $id=$_GET['excluir'];
	require_once('read.php');
	require_once('create.php');
	require_once('update.php');
	require_once('delete.php');
	require_once('edit.php');
	require_once('conexao.php');
?>
<!DOCTYPE html>
<html lang="pt-br">
	<head>
		<meta charset="UTF-8">
		<title>Gestão de Aniversariantes</title>
		<link rel="stylesheet" href="estilo.css">
	</head>

	<body>
		<h2>Gestão de Aniversariantes</h2>
		<form method="GET" action="index.php">
			<fieldset>
				<legend>Cadastrar Aniversariante</legend>
				<label>Nome:</label>
				<input type="text"    name="nome" style="text-transform: uppercase;" value="<?php echo $nome; ?>">
				<label>Data de Nascimento:</label>
				<input type="date"    name="data_nascimento" value="<?php echo $dtNasc; ?>" style="margin-bottom:20px;">
				<input type="hidden"  name="id" value="	<?php echo $id; ?>">
				<?php
					if (isset($_GET['bEditar']))  echo "<button type='submit' name='bAtualizar'    value='$id'>Salvar Alterações</button>";
					if (isset($_GET['bEditar']))  echo "<a href='index.php'>Cancelar</a>";
					if (!isset($_GET['bEditar'])) echo "<button type='submit' name='bCadastrar' value='0'>Cadastrar Aniversariante</button>";
				?>
			</fieldset>
			<h3>Lista de Aniversariantes Registrados</h3>
			<table>
				<thead>
					<tr>
						<th>ID</th>
						<th>Nome</th>
						<th>Data de Nascimento</th>
						<th>Ações</th>
					</tr>
				</thead>
				<tbody>
					<?php
						echo $tabela;
					?>
				</tbody>
			</table>
		</form>
	</body>
</html>

<?php
	mysqli_close($conn);
?>
estilo.css
        /* Reset de estilos básicos e definição do Box Model */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        /* Ocupa 100% da largura e altura do Viewport */
        body {
            background-color: #f4f6f9;
            color: #333;
            width: 100vw;
            min-height: 100vh;
            padding: 2rem;
        }

        h2 {
            color: #1e293b;
            margin-bottom: 1.5rem;
            font-size: 1.8rem;
            font-weight: 600;
        }

        h3 {
            color: #475569;
            margin: 2.5rem 0 1rem 0;
            font-size: 1.4rem;
        }

        fieldset {
            background: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            margin-bottom: 2rem;
            width: 100%;
        }

        legend {
            font-weight: 600;
            color: #000000;
            padding: 0 0.5rem;
            font-size: 1.1rem;
        }

        /* Layout do Formulário em Linha/Grid Moderno */
        form {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            align-items: flex-end;
            width: 100%;
        }

        form .form-group {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
            flex: 1;
            min-width: 200px;
        }

        label {
            font-size: 0.85rem;
            font-weight: 600;
            color: #64748b;
        }

        input[type="text"],
        input[type="date"] {
            width: 100%;
            padding: 0.65rem 0.75rem;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            font-size: 0.95rem;
            color: #334155;
            background-color: #fff;
            transition: border-color 0.2s, box-shadow 0.2s;
        }

        input[type="text"]:focus,
        input[type="date"]:focus {
            outline: none;
            border-color: #2563eb;
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
        }

        /* Botões do Formulário */
        button[type="submit"] {
            background-color: #2563eb;
            color: #ffffff;
            border: none;
            padding: 0.65rem 1.5rem;
            font-size: 0.95rem;
            font-weight: 600;
            border-radius: 6px;
            cursor: pointer;
            transition: background-color 0.2s;
            height: 42px;
        }

        button[type="submit"]:hover {
            background-color: #1d4ed8;
        }

        form a {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            height: 42px;
            padding: 0.65rem 1.25rem;
            color: #64748b;
            text-decoration: none;
            font-size: 0.95rem;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            background: #fff;
            transition: background-color 0.2s;
        }

        form a:hover {
            background-color: #f8fafc;
            color: #334155;
        }

        /* Tabela Moderna e Responsiva */
        table {
            width: 100%;
            border-collapse: collapse;
            background: #ffffff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            border: 1px solid #e2e8f0;
        }

        th, td {
            padding: 1rem;
            text-align: left;
            font-size: 0.95rem;
        }

        th {
            background-color: #f8fafc;
            color: #475569;
            font-weight: 600;
            border-bottom: 2px solid #e2e8f0;
        }

        td {
            color: #334155;
            border-bottom: 1px solid #f1f5f9;
        }

        tr:last-child td {
            border-bottom: none;
        }

        tr:hover td {
            background-color: #f8fafc;
        }

        /* Estilização das Ações na Tabela */
        .btn {
            display: inline-block;
            padding: 0.4rem 0.75rem;
            text-decoration: none;
            border-radius: 6px;
            font-size: 0.85rem;
            font-weight: 600;
            margin-right: 0.5rem;
            transition: opacity 0.2s;
        }

        .btn:hover {
            opacity: 0.9;
        }

        .btn-edit {
            background-color: #fef3c7;
            color: #d97706;
        }

        .btn-del {
            background-color: #fee2e2;
            color: #dc2626;
        }

        /* Mensagens de Feedback */
        .msg {
            padding: 1rem;
            background-color: #dcfce7;
            color: #15803d;
            border-left: 4px solid #16a34a;
            margin-bottom: 1.5rem;
            border-radius: 4px;
            font-size: 0.95rem;
            font-weight: 500;
            width: 100%;
        }
conexao.php (Apenas Leitura)
<?php
	$host = 'localhost';
	$user = 'root';
	$pass = '';
	$db   = 'etecvav';
	$conn = mysqli_connect($host, $user, $pass, $db);
	mysqli_set_charset($conn, "utf8");
?>
funcoes.php (Apenas Leitura)
<?php
	function capitalizar(string $nome): string {
		$nome = mb_convert_case(trim($nome), MB_CASE_TITLE, "UTF-8");

		$procurar   = [' Da ', ' De ', ' Di ', ' Do ', ' Du ', ' Das ', ' Des ', ' Dis ', ' Dos ', ' E ', ' O '];
		$substituir = [' da ', ' de ', ' di ', ' do ', ' du ', ' das ', ' des ', ' dis ', ' dos ', ' e ', ' o ' ];
		
		return str_replace($procurar, $substituir, $nome);
	}

	function minusculas($texto) {
		return mb_strtolower($texto, "UTF-8");
	}

	function maiusculas($texto) {
		return mb_strtoupper($texto, "UTF-8");
	}
?>
edit.php (Apenas Leitura)
<?php
	$resultado = null;
	$nome      = "";
	$dtNasc    = "";
	if (isset($_GET['bEditar'])) {
		$id = $_GET['bEditar'];
		$result = mysqli_query($conn, "SELECT * FROM pessoas WHERE id = $id");
		if ($result && mysqli_num_rows($result) > 0) {
			$resultado = mysqli_fetch_assoc($result);
			$nome   = $resultado['nome'];
			$dtNasc = $resultado['data_nascimento'];
		}
	}
?>
delete.php (Apenas Leitura)
<?php
	if (isset($_GET['bExcluir'])) {
		$id = $_GET['bExcluir'];
		$sql = "DELETE FROM pessoas WHERE id = $id";
		mysqli_query($conn, $sql);
	}
?>
create.php (Apenas Leitura)
<?php
	if (isset($_GET['bCadastrar'])) {
		$id = 0;
		$nome = $_GET['nome'];
		$data_nascimento = $_GET['data_nascimento'];
		$sql = "INSERT INTO pessoas (nome, data_nascimento) VALUES ('$nome', '$data_nascimento')";
		mysqli_query($conn, $sql);
	}
?>
Atualizar Visualização