-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit_department.php
More file actions
59 lines (50 loc) · 1.51 KB
/
edit_department.php
File metadata and controls
59 lines (50 loc) · 1.51 KB
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
<?php
// including the database connection file
include_once("config.php");
if(isset($_POST['update']))
{
$department_id = mysqli_real_escape_string($con, $_POST['id']);
$department_name = mysqli_real_escape_string($con, $_POST['department_name']);
// checking empty fields
if(empty($department_name)) {
echo "<font color='red'>Name field is empty.</font><br/>";
} else {
//updating the table
$result = mysqli_query($con, "UPDATE department SET department_name='$department_name' WHERE department_id=$department_id");
//redirectig to the display page. In our case, it is index.php
header("Location: index.php");
}
}
?>
<?php
//getting id from url
$id = $_GET['id'];
//selecting data associated with this particular id
$result = mysqli_query($con, "SELECT * FROM department WHERE department_id=$id");
while($res = mysqli_fetch_array($result))
{
$department_name = $res['department_name'];
$department_id = $res['department_id'];
}
?>
<html>
<head>
<title>Edit Department</title>
</head>
<body>
<a href="index.php">Home</a>
<br/><br/>
<form name="form1" method="post" action="edit_department.php">
<table border="0">
<tr>
<td>Name</td>
<td><input type="text" name="department_name" value="<?php echo $department_name;?>"></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>