-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclients.php
87 lines (66 loc) · 2.44 KB
/
clients.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
77
78
79
80
81
82
83
84
85
86
87
<?php
session_start();
// if user is not logged in
if( !$_SESSION['loggedInUser'] ) {
// send them to the login page
header("Location: index.php");
}
// connect to database
include('includes/connection.php');
// query & result
$query = "SELECT * FROM clients";
$result = mysqli_query( $conn, $query );
// check for query string
if( isset( $_GET['alert'] ) ) {
// new client added
if( $_GET['alert'] == 'success' ) {
$alertMessage = "<div class='alert alert-success'>New client added!<a class='close' data-dismiss='alert'>×</a></div>";
} elseif( $_GET['alert'] == 'updatesuccess' ) { // cient updated
$alertMessage = "<div class='alert alert-success'>Client updated!<a class='close' data-dismiss='alert'>×</a></div>";
} elseif( $_GET['alert'] == 'deleted' ) { // cient deleted
$alertMessage = "<div class='alert alert-success'>Client deleted!<a class='close' data-dismiss='alert'>×</a></div>";
}
}
// close the mysql connection
mysqli_close($conn);
include('includes/header.php');
?>
<h1>Client Address Book</h1>
<?php echo $alertMessage; ?>
<table class="table table-striped table-bordered">
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>Company</th>
<th>Notes</th>
<th>Edit</th>
</tr>
<?php
if( mysqli_num_rows($result) > 0 ) {
// we have data!
// output the data
while( $row = mysqli_fetch_assoc($result) ) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>
<td>" . $row['email'] . "</td>
<td>" . $row['phone'] . "</td>
<td>" . $row['address'] . "</td>
<td>" . $row['company'] . "</td>
<td>" . $row['notes'] . "</td>";
echo '<td><a href="edit.php?id=' . $row['id'] . '" type="button" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit"></span></a></td>';
echo "</tr>";
}
} else { // if no entries
echo "<div class='alert alert-warning'>You have no clients!</div>";
}
mysqli_close($conn);
?>
<tr>
<td colspan="7"><div class="text-center"><a href="add.php" type="button" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-plus"></span> Add Client</a></div></td>
</tr>
</table>
<?php
include('includes/footer.php');
?>