-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
72 lines (62 loc) · 1.84 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
65
66
67
68
69
70
71
72
<?php
include_once("db.php");
if(isset($_POST['update']))
{
$id = $_POST['id'];
$name=$_POST['name'];
$age=$_POST['age'];
$email=$_POST['email'];
if(empty($name) || empty($age) || empty($email)) {
if(empty($name)) {
echo "<font color='red'>Name field is empty.</font><br/>";
}
if(empty($age)) {
echo "<font color='red'>Age field is empty.</font><br/>";
}
if(empty($email)) {
echo "<font color='red'>Email field is empty.</font><br/>";
}
} else {
$result = pg_query("UPDATE users SET name='$name',age='$age',email='$email' WHERE id='$id'");
header("Location: users.php");
}
}
?>
<?php
$id = $_GET['id'];
$result = pg_query("SELECT * FROM users WHERE id='$id'") or die("Failed");
while($res = pg_fetch_row($result)) {
$name = $res[1];
$age = $res[3];
$email = $res[2];
}
?>
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<a href="users.php">Home</a>
<br/><br/>
<form name="form1" 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>Age</td>
<td><input type="text" name="age" value="<?php echo $age;?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $email;?>"></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>