-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit.php
65 lines (57 loc) · 1.53 KB
/
edit.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
<?php
// include_once db connection file
include_once("config.php");
// Check if form is submitted for user update, then redirect to homepage after update
if(isset($_POST['update']))
{
$id = $_POST['id'];
$name=$_POST['name'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
// update user data
$result = mysqli_query($mysqli, "UPDATE users SET name='$name',email='$email',mobile='$mobile' WHERE id=$id");
// Redirect to homepage to display updated user in list
header("Location: index.php");
}
?>
<?php
// Display selected user data based on id
// Getting id from url
$id = $_GET['id'];
// Fetech user data based on id
$result = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id");
while($user_data = mysqli_fetch_array($result))
{
$name = $user_data['name'];
$email = $user_data['email'];
$mobile = $user_data['mobile'];
}
?>
<html>
<head>
<title> Edit User Data </title>
</head>
<body>
<a href="index.php">Home</a> <br/><br/>
<form name="update_user" method="post" action="edit.php">
<table border="0">
<tr>
<td>Name</td>
<td><input type="text" name="name" value=<?php echo $name;?>></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value=<?php echo $email;?>></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="text" name="mobile" value=<?php echo $mobile;?>></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>