-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
76 lines (60 loc) · 2.01 KB
/
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
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
70
71
72
73
74
75
76
<?php
include "inc/header.php";
include "config/database.php";
try {
$query = $connection->prepare("SELECT *FROM employees ORDER BY id ASC");
$query->execute();
$query->setFetchMode(PDO::FETCH_ASSOC);
$data = $query->fetchAll();
// var_dump($data);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
<div class="bottom-margin">
<a href="create.php"><button>Create Record</button></a>
</div>
<?php
if($data > 0):
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["name"]) && empty($_POST["email"]) && empty($_POST["website"])){
echo "<p class='error'>Please fill up the required field!</p>";
} else {
header("Location:index.php");
}
}
?>
<div class="data-container">
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Website</th>
<th>Image</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php foreach($data as $data) : ?>
<tr>
<td><?php echo ucwords($data['name']); ?></td>
<td><?php echo $data['email']; ?></td>
<td><?php echo $data['website']; ?></td>
<td>
<img src="<?php echo $data['image_path']; ?>" alt="" class="index-image">
</td>
<td>
<a href="edit.php?id=<?php echo $data['id']; ?>">Edit</a>
</td>
<td>
<a href="delete.php?id=<?php echo $data['id']; ?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php
else:
echo "<h2>There is no record!</h2>";
endif;
include "inc/footer.php";
?>