Created
May 19, 2025 22:37
-
-
Save uchoamaster/4410e9cb2af8dd4033ced15751fbabc2 to your computer and use it in GitHub Desktop.
index com css projeto agenda v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Incluir arquivo de conexão | |
require_once 'config/database.php'; | |
// Verificar se há mensagem de sucesso | |
$success_message = ''; | |
if (isset($_GET['success'])) { | |
switch ($_GET['success']) { | |
case 'create': | |
$success_message = 'Contato adicionado com sucesso!'; | |
break; | |
case 'update': | |
$success_message = 'Contato atualizado com sucesso!'; | |
break; | |
case 'delete': | |
$success_message = 'Contato excluído com sucesso!'; | |
break; | |
} | |
} | |
// Consulta para selecionar todos os contatos | |
$sql = "SELECT * FROM contatos ORDER BY nome ASC"; | |
$result = mysqli_query($conn, $sql); | |
// Verificar se há erros na consulta | |
if (!$result) { | |
die("Erro na consulta: " . mysqli_error($conn)); | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="pt-br"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Agenda Telefônica</title> | |
<link rel="stylesheet" href="assets/css/style.css"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> | |
</head> | |
<body> | |
<header> | |
<div class="container"> | |
<div class="header-content"> | |
<div class="logo"> | |
<i class="fas fa-address-book fa-2x"></i> | |
<h1>Agenda Telefônica</h1> | |
</div> | |
<a href="create.php" class="btn btn-success"> | |
<i class="fas fa-plus"></i> Novo Contato | |
</a> | |
</div> | |
</div> | |
</header> | |
<div class="container"> | |
<?php if (!empty($success_message)): ?> | |
<div class="alert alert-success"> | |
<?php echo $success_message; ?> | |
</div> | |
<?php endif; ?> | |
<h2>Lista de Contatos</h2> | |
<div class="table-container"> | |
<?php if (mysqli_num_rows($result) > 0): ?> | |
<table> | |
<thead> | |
<tr> | |
<th>ID</th> | |
<th>Nome</th> | |
<th>Telefone</th> | |
<th>Email</th> | |
<th>Data de Cadastro</th> | |
<th>Ações</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php while ($row = mysqli_fetch_assoc($result)): ?> | |
<tr> | |
<td><?php echo $row['id']; ?></td> | |
<td><?php echo $row['nome']; ?></td> | |
<td><?php echo $row['telefone']; ?></td> | |
<td><?php echo $row['email']; ?></td> | |
<td><?php echo date('d/m/Y H:i', strtotime($row['data_cadastro'])); ?></td> | |
<td class="actions"> | |
<a href="edit.php?id=<?php echo $row['id']; ?>" class="btn btn-warning"> | |
<i class="fas fa-edit"></i> Editar | |
</a> | |
<a href="delete.php?id=<?php echo $row['id']; ?>" class="btn btn-danger" | |
onclick="return confirm('Tem certeza que deseja excluir este contato?');"> | |
<i class="fas fa-trash"></i> Excluir | |
</a> | |
</td> | |
</tr> | |
<?php endwhile; ?> | |
</tbody> | |
</table> | |
<?php else: ?> | |
<div class="empty-message"> | |
<i class="fas fa-info-circle fa-2x"></i> | |
<p>Nenhum contato encontrado. Clique em "Novo Contato" para adicionar.</p> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> | |
<?php | |
// Fechar conexão | |
mysqli_close($conn); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment