-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
82 lines (76 loc) · 2.71 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
include("connect.php");
// Initialize variables
$id = $name = $email = $mobile = $password = "";
// Check if the updateid parameter is set
if(isset($_GET['updateid'])){
$id = $_GET['updateid'];
// Fetch the current user data
$sql = "SELECT * FROM `crud` WHERE id=$id";
$result = mysqli_query($conn, $sql);
if($result){
$row = mysqli_fetch_assoc($result);
$name = $row['name'];
$email = $row['email'];
$mobile = $row['mobile'];
$password = $row['password'];
} else {
echo 'User not found';
exit();
}
}
// Update user data
if(isset($_POST['btnsubmit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$password = $_POST['password'];
// Update query
$sql = "UPDATE `crud` SET name='$name', email='$email', mobile='$mobile', password='$password' WHERE id=$id";
$result = mysqli_query($conn, $sql);
if($result){
echo "Data updated successfully";
} else {
echo 'Error: ' . mysqli_error($conn);
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Crud</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>
<style>
.btn a {
text-decoration: none !important;
}
</style>
<body>
<div class="container">
<h1 class='mt-4'>Update user</h1>
<button class="btn btn-secondary my-5 btn-lg"><a href="display.php" class="text-light">Data Table</a></button>
<form method="post">
<div class="form-group mb-3">
<label>Name</label>
<input type="text" name="name" class="form-control" value="<?php echo $name; ?>" placeholder="Enter your name">
</div>
<div class="form-group mb-3">
<label>Email</label>
<input type="text" name="email" class="form-control" value="<?php echo $email; ?>" placeholder="Enter your email">
</div>
<div class="form-group mb-3">
<label>Mobile</label>
<input type="text" name="mobile" class="form-control" value="<?php echo $mobile; ?>" placeholder="Mobile number">
</div>
<div class="form-group mb-3">
<label>Password</label>
<input type="text" name="password" class="form-control" value="<?php echo $password; ?>" placeholder="Password">
</div>
<button name="btnsubmit" type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</body>
</html>