-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.php
62 lines (49 loc) · 1.27 KB
/
update.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
<?php include 'db.php';
$query = "SELECT * FROM Users";
$result = mysqli_query($conn, $query);
if (!$result) {
die('Query failed');
}
?>
<?php
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$id = $_POST['id'];
//Update the records in db
$query = "UPDATE Users SET ";
$query .= "username = '$username', ";
$query .= "password = '$password' ";
$query .= "WHERE id = $id";
$result = mysqli_query($conn, $query);
if (!$result) {
die("Update query failed" . mysqli_error($conn));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PHP CRUD App</title>
</head>
<body>
<form action="update.php" method="post">
<label for="username"> Username </label>
<input type="text" name="username">
<label for="password"> Password </label>
<input type="password" name="password">
<select name="id" id="">
<?php
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
echo "<option value='$id'>$id</option>";
}
?>
</select>
<input type="submit" name="submit" value="UPDATE">
</form>
</body>
</html>