-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
41 lines (38 loc) · 1020 Bytes
/
index.php
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
<?php
// Include the database connection file
include_once("config.php");
class Contact {
public $id;
public $name;
public $age;
public $email;
}
// Fetch contacts (in descending order)
$contacts = $pdo->query( "SELECT * FROM contacts ORDER BY id DESC")->fetchAll(PDO::FETCH_CLASS, 'Contact');
?>
<html>
<head>
<title>MariaDB Rolodex</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<table>
<tr>
<td>Name</td>
<td>Age</td>
<td>Email</td>
<td><a class="button" href="add.php">Add Contact</a></td>
</tr>
<?php
// Print contacts
foreach($contacts as $contact) {
echo "<tr>";
echo "<td>".$contact->name."</td>";
echo "<td>".$contact->age."</td>";
echo "<td>".$contact->email."</td>";
echo "<td><a href=\"edit.php?id=$contact->id\">Edit</a> | <a href=\"delete.php?id=$contact->id\" onClick=\"return confirm('Are you sure you want to delete this contact?')\">Delete</a></td>";
}
?>
</table>
</body>
</html>