-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
69 lines (63 loc) · 2.53 KB
/
Copy pathindex.php
File metadata and controls
69 lines (63 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// Include database connection and helper functions
require_once 'config/db.php';
require_once 'includes/functions.php';
// Get all contacts
$contacts = getAllContacts();
// Handle search query
if (isset($_GET['search']) && !empty($_GET['search'])) {
$searchQuery = $_GET['search'];
$contacts = searchContacts($searchQuery);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Contacts App</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="container">
<h1>Contacts</h1>
<div class="actions">
<a href="add.php" class="btn">Add New Contact</a>
<form action="index.php" method="GET" class="search-form">
<input type="text" name="search" placeholder="Search contacts..." value="<?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?>">
<button type="submit">Search</button>
<?php if (isset($_GET['search']) && !empty($_GET['search'])): ?>
<a href="index.php">Clear</a>
<?php endif; ?>
</form>
</div>
<?php if (empty($contacts)): ?>
<p>No contacts found.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($contacts as $contact): ?>
<tr>
<td><?php echo htmlspecialchars($contact['first_name'] . ' ' . $contact['last_name']); ?></td>
<td><?php echo htmlspecialchars($contact['phone']); ?></td>
<td><?php echo htmlspecialchars($contact['email']); ?></td>
<td>
<a href="edit.php?id=<?php echo $contact['id']; ?>" class="btn-edit">Edit</a>
<a href="delete.php?id=<?php echo $contact['id']; ?>" class="btn-delete" onclick="return confirm('Are you sure you want to delete this contact?');">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</body>
</html>