-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
216 lines (189 loc) · 7.19 KB
/
index.php
File metadata and controls
216 lines (189 loc) · 7.19 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php include('includes/header.php')
?>
<!--here starts the first container-->
<div class="container my-5">
<form method="post">
<input type="text" name="search" placeholder="Search Anything ...">
<button type="submit" name="validate" class="btn btn-info">Search</button>
</form>
</div>
<div class="container1" id="userTable">
<button class="btn btn-info my-5" id="addbtn">Add User</button>
<table class="table">
<thead>
<tr>
<th scope="col">User ID</th>
<th scope="col">User Name</th>
<th scope="col">User Email</th>
<th scope="col">User Type</th>
<th scope="col">Operations</th>
</tr>
</thead>
<tbody class="table-group-divider">
<?php
include 'config/dbcon.php'; // Use include instead of @include to see any errors
if(isset($_POST['validate'])){
$inputValue=$_POST['search'];
$sql="select * from users where user_id = '$inputValue' or user_name = '$inputValue' or user_email= '$inputValue' or user_type= '$inputValue'";
$query=mysqli_query($conn,$sql);
if($query){
while ($row=mysqli_fetch_assoc($query)) {
$user_id = $row['user_id'];
$user_name = $row['user_name'];
$user_email = $row['user_email'];
$user_type = $row['user_type'];
echo '<tr>
<td>' . $user_id . '</td>
<td>' . $user_name . '</td>
<td>' . $user_email . '</td>
<td>' . $user_type . '</td>
<td>
<button class="btn btn-info text-white"><a style="text-decoration:none;"
href="update.php?updateid='.$user_id.'">update</a></button>
<button class="btn btn-info text-white"><a
style="text-decoration:none; href="delete.php?deletedid='.$user_id.'">delete</a></button>
</td>
</tr>';
// code...
}
}
}else{
$sql = "select * from users";
$result = mysqli_query($conn, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$user_id = $row['user_id'];
$user_name = $row['user_name'];
$user_email = $row['user_email'];
$user_type = $row['user_type'];
echo '<tr>
<td>' . $user_id . '</td>
<td>' . $user_name . '</td>
<td>' . $user_email . '</td>
<td>' . $user_type . '</td>
<td>
<button class="btn text-white btn-info"><a href="update.php?updateid='.$user_id.'">update</a></button>
<button class="btn text-white btn-info"><a href="delete.php?deletedid='.$user_id.'">delete</a></button>
</td>
</tr>';
}
}
}
?>
</tbody>
</table>
</div>
<!--the script-->
<script>
// JavaScript code to handle navigation between sections
document.addEventListener("DOMContentLoaded", function() {
// Find the "Add User" button or link (replace 'addUserButton' with the actual id or class of your button/link)
var addUserButton = document.getElementById("adduserButton");
// Add click event listener
addUserButton.addEventListener("click", function(event) {
event.preventDefault(); // Prevent default action of the button/link
// Scroll to the addUserSection
document.getElementById("userTable").scrollIntoView({
behavior: "smooth" // You can change this to "auto" for instant scrolling
});
});
// Handle form submission
var addUserForm = document.getElementById("addUserForm");
addUserForm.addEventListener("submit", function(event) {
// After the form is submitted, scroll back to the table
document.getElementById("userTable").scrollIntoView({
behavior: "smooth" // You can change this to "auto" for instant scrolling
});
});
});
</script>
<script>
// JavaScript code to handle the click event and scroll to the addUserSection
document.addEventListener("DOMContentLoaded", function() {
// Find the "Add User" button or link (replace 'addUserButton' with the actual id or class of your button/link)
var addUserButton = document.getElementById("addbtn");
// Add click event listener
addUserButton.addEventListener("click", function(event) {
event.preventDefault(); // Prevent default action of the button/link
// Scroll to the addUserSection
document.getElementById("add_user").scrollIntoView({
behavior: "smooth" // You can change this to "auto" for instant scrolling
});
});
});
</script>
<!--the script-->
<!--here ends the first container-->
<!--here starts the second container-->
<div class="container" id="add_user">
<div class="row">
<div class="col-md-12">
<?php
@include 'config/dbcon.php';
if(isset($_POST['submit'])){
$user_name = mysqli_real_escape_string($conn, $_POST['user_name']);
$user_email = mysqli_real_escape_string($conn, $_POST['user_email']);
$pass = md5($_POST['password']);
$cpass = md5($_POST['cpassword']);
$user_type = $_POST['user_type'];
$select = " SELECT * FROM users WHERE user_email = '$user_email' && user_password= '$pass' ";
$result = mysqli_query($conn, $select);
if(mysqli_num_rows($result) > 0){
$error[] = 'user already exist!';
}else{
if($pass != $cpass){
$error[] = 'password not matched!';
}else{
$insert = "INSERT INTO users(user_name, user_email, user_password, user_type) VALUES('$user_name','$user_email','$pass','$user_type')";
mysqli_query($conn, $insert);
# header('location:login_form.php');
}
}
};
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management</title>
<!-- custom css file link -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="assets/css/style.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="bc">
<div class="form-container">
<form action="" method="post">
<h3>Add user</h3>
<?php
if(isset($error)){
foreach($error as $error){
echo '<span class="error-msg">'.$error.'</span>';
};
};
?>
<input type="text" name="user_name" required placeholder="enter the user name">
<input type="email" name="user_email" required placeholder="enter the email">
<input type="password" name="password" required placeholder="enter your password">
<input type="password" name="cpassword" required placeholder="confirm your password">
<select name="user_type">
<option value="user">user</option>
<option value="admin">admin</option>
</select>
<input type="submit" class="bg-info" name="submit" value="register now" class="form-btn">
<!--<p>already have an account? <a href="login_form.php">login now</a></p>-->
</form>
</div>
</div>
</body>
</html>
</div>
</div>
</div>
<!--here ends the second container-->
<!--update division ends here -->
<?php include('includes/footer.php') ?>