forked from prodgrammer21/PHP-CRUD-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
68 lines (59 loc) · 1.81 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
63
64
65
66
67
68
<?php
require('./database.php');
if (isset($_POST["edit"])) {
$editId = $_POST['editId'];
$editUsername = $_POST['editUsername'];
$editPassword = $_POST['editPassword'];
}
if (isset($_POST['update'])) {
$updateId = $_POST['updateId'];
$updateUsername = $_POST['updateUsername'];
$updatePassword = $_POST['updatePassword'];
$queryUpdate = "UPDATE accounts SET username = '$updateUsername', password = '$updatePassword' WHERE id = $updateId";
$sqlUpdate = mysqli_query($connection, $queryUpdate);
echo '<script>alert("Successfully updated!")</script>';
echo '<script>window.location.href = "/php-crud-tutorial/index.php"</script>';
}
?>
<!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>Update</title>
</head>
<style>
html, body {
margin: 0;
padding: 0;
}
.main {
height: 100vh;
/* Grid */
display: grid;
grid-template-rows: auto 1fr;
justify-items: center;
row-gap: 20px;
}
.main .update-main {
grid-row: 1/2;
display: grid;
grid-auto-rows: auto;
row-gap: 5px;
}
.main .update-main h3 {
text-align: center;
}
</style>
<body>
<div class="main">
<form class="update-main" action="/php-crud-tutorial/update.php" method="post">
<h3>UPDATE USER:</h3>
<input type="text" name="updateUsername" placeholder="Enter username" value="<?php echo $editUsername ?>" required/>
<input type="password" name="updatePassword" placeholder="Enter password" value="<?php echo $editPassword ?>"required/>
<input type="submit" name="update" value="UPDATE" />
<input type="hidden" name="updateId" value="<?php echo $editId?>" />
</form>
</body>
</html>