-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-group.php
110 lines (101 loc) · 3.58 KB
/
add-group.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add group</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head> -->
<?php
session_start();
if (isset($_SESSION['id'])) {
$user_id = $_SESSION['id'];
$title = 'Add Group';
include ('./header.php');
include './connection.php';
// print $_POST['group-name'];
// $_POST['group-name'] = '';
// print $_POST['group-name'];
// print '<br>';
if (isset($_POST['submit']) and isset($_POST['group-name'])) {
print 'phase 1';
$groupName = $_POST['group-name'];
// $checkGroupQuery = "SELECT * FROM group_details WHERE groupName = '$groupName'";
$checkGroupQuery = "SELECT * FROM group_details WHERE groupName = '$groupName' AND user_id = '$user_id'";
$checkGroupExists = $con -> query($checkGroupQuery);
if ($checkGroupExists -> num_rows > 0) {
echo 'the group name already exists please choose another!';
} else {
// $insertIntoGroup = "INSERT INTO group_details (groupName) VALUES ('$groupName')";
$insertIntoGroup = "INSERT INTO group_details (user_id, groupName) VALUES ('$user_id', '$groupName')";
$result = $con -> query($insertIntoGroup);
if ($result) {
print 'Group created successfully!';
// unset($_POST['group-name']);
// unset($groupName);
print '<br>';
// print $groupName;
header('location: ./add-group.php');
} else {
print 'fail';
}
}
}
// $showGroupsQuery = "SELECT * FROM group_details";
$showGroupsQuery = "SELECT * FROM group_details WHERE user_id = '$user_id'";
$showGroups = $con -> query($showGroupsQuery);
?>
<body>
<div class="container">
<form class="col s12" method="POST">
<div class="row">
<div class="center">
<div class="input-field col s4">
<input id="group-name" type="text" class="validate" name="group-name" required>
<label for="group-name">Group Name</label>
</div>
<div class="input-field col">
<input class="input-btn input-field btn" type="submit" value="submit" name="submit">
</div>
</div>
</div>
</form>
<?php
if ($showGroups -> num_rows > 0) {
?>
<div class="row">
<table>
<thead>
<tr>
<th>Group Id</th>
<th>Group Name</th>
<th>Add Contact(s)</th>
<th>View Saved Contacts</th>
</tr>
</thead>
<tbody>
<?php
while($row=$showGroups->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['groupId']; ?></td>
<td><?php echo $row['groupName']; ?></td>
<td><a href="./add-to-group.php?groupId=<?php echo $row['groupId']; ?>" class="waves-effect waves-light btn">+</a></td>
<td><a href="./view-group-contacts.php?groupId=<?php echo $row['groupId']; ?>" class="waves-effects waves-light btn">View</a></td>
</tr>
<?php
}
} else {
print 'no groups exist, add some!';
}
} else {
header('location: ./index.php');
}
?>
</table>
</div>
</div>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>