Repository navigation
Expand file tree
/
Copy pathedit_student.php
More file actions
83 lines (76 loc) · 2.98 KB
/
Copy pathedit_student.php
File metadata and controls
83 lines (76 loc) · 2.98 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<title>edit student info</title>
</head>
<body>
<?php include 'connection.php'; ?>
<?php
$std_id = $_REQUEST['id'];
//echo $std_id;
$query = "SELECT * FROM student WHERE id = $std_id";
$sql = mysqli_query($conn, $query);
$student = mysqli_fetch_array($sql);
?>
<div class = "container">
<div>
<h2>create Student</h2>
</div>
<div class = "col-md-7">
<form method = "post" action = "">
<div class="form-group">
<label for="">Student Name</label>
<input type="text" value = "<?php echo $student['name'] ?>" class="form-control" name="name" id="">
</div>
<div class="form-group">
<label for="">Email</label>
<input type="email" value = "<?php echo $student['email'] ?>" class="form-control" name="email" id="">
</div>
<div class="form-group">
<label for="">Date of Birth</label>
<input type="date"value = "<?php echo $student['dob'] ?>" class="form-control" name="dob" id="">
</div>
<div class="form-group">
<label for="">Department</label>
<select name="dept_id" id="" class="form-control">
<?php
$query = "SELECT id, short_code FROM departments";
$sql = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($sql))
{ ?>
<option <?php echo ($row['id']==$student['department_id'])? 'selected' : '' ?> value="<?php echo $row['id'] ?>" > <?php echo $row['short_code'] ?> </option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary" value="update">
</div>
</form>
</div>
</div>
</body>
</html>
<?php
include 'connection.php';
if(isset($_POST['submit']))
{
//recvd data from input/control
$name = $_POST['name'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$dept_id = $_POST['dept_id'];
//db query
$query = "UPDATE student SET name='$name', email='$email', dob='$dob', department_id='$dept_id' WHERE id ='$std_id'";
$sql = mysqli_query($conn, $query);
if($sql)
{
header('Location: show_student.php');
echo "success!!";
}
}
?>