forked from WorkofAditya/PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXTRA.PHP
More file actions
74 lines (74 loc) · 1.74 KB
/
EXTRA.PHP
File metadata and controls
74 lines (74 loc) · 1.74 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
Db.php
<?php
$conn = mysqli_connect("localhost", "root", "", "classb");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
index.php
<?php include 'db.php'; ?>
<!DOCTYPE html>
<html>
<head>
<title>User List</title>
</head>
<body>
<h2>User List</h2>
<a href="insert.php">Add New User</a>
<br><br>
<table border="1" cellpadding="10">
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Action</th>
</tr>
<?php
$result = mysqli_query($conn, "SELECT * FROM users");
while($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['age']; ?></td>
<td>
<a href="update.php?id=<?php echo $row['id']; ?>">Edit</a> |
<a href="delete.php?id=<?php echo $row['id']; ?>"
onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
insert.php
<?php
include 'db.php';
if(isset($_POST['save'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$age = $_POST['age'];
mysqli_query($conn, "INSERT INTO users(name,email,age)
VALUES('$name','$email','$age')");
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add User</title>
</head>
<body>
<h2>Add User</h2>
<form method="POST">
Name: <input type="text" name="name" required><br><br>
Email: <input type="email" name="email" required><br><br>
Age: <input type="number" name="age" required><br><br>
<button type="submit" name="save">Save</button>
</form>
<br>
<a href="index.php">Back to List</a>
</body>
</html>