-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserdetails.php
86 lines (70 loc) · 2.06 KB
/
userdetails.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="FormDesign.css" />
<script type="text/javascript" src="FormValidation.js"></script>
<title>User Details</title>
</head>
<body>
<?php
include 'dbconnect.php';
$name = $_POST['uname'];
$password = $_POST['password'];
$email = $_POST['email'];
$country = $_POST['country'];
if(isset($_POST['uname']) && isset($_POST['password'])) {
$sql = "INSERT INTO `employees`(`name`, `password`, `email`, `country`) VALUES ('$name', '$password', '$email', '$country')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$sql = "SELECT `id`, `name`, `password`, `email`, `country` FROM `employees`";
$result = $conn->query($sql);
if(isset($_GET['id'])) {
// sql to delete a record
$sql = "DELETE FROM employees WHERE id=".$_GET['id'];
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
}
?>
<h2>Employess List</h2>
<table border='1' cellpadding="5" cellspacing="5">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Password</th>
<th>Email</th>
<th>Country</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['password']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['country']."</td>";
echo "<td><a href='userdetails.php?id=".$row['id']."'>Delete</a></td>";
echo "</tr>";
}
} else {
echo "<td colspan='6'>No records Found</td>";
}
mysqli_close($conn);
?>
</tbody>
</table>
</body>
</html>