-
Notifications
You must be signed in to change notification settings - Fork 2
/
edit.php
52 lines (51 loc) · 1.48 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
<?php
require "core.php";
if(!isset($_GET["id"])) {
header("Location: index.php");
exit();
}
$stu_id = $_GET["id"];
$sql = "SELECT * FROM `student` WHERE `stu_id` = " . $stu_id . " LIMIT 1";
$result = $mysqli->query($sql);
if($result->num_rows > 0) {
if(isset($_POST["edit"])) {
$sql = "UPDATE `student` set stu_name = '". $_POST["stu_name"] ."',
stu_family = '". $_POST["stu_family"] ."',
stu_age = ". $_POST["stu_age"] .",
stu_birthdate = '". $_POST["stu_birthdate"] ."',
stu_address = '". $_POST["stu_address"] ."'
where stu_id = " . $stu_id;
if($mysqli->query($sql)) {
printf("Table student updated successfully.<br>\n");
}
if ($mysqli->errno) {
printf("Could not update table: %s<br>\n", $mysqli->error);
}
}
while($row = $result->fetch_assoc()) {
?>
<h1>Edit the student:</h1>
<form action="" method="POST">
<b>Name:</b>
<input type="text" name="stu_name" value="<?= $row["stu_name"] ?>">
<br>
<b>Family:</b>
<input type="text" name="stu_family" value="<?= $row["stu_family"] ?>">
<br>
<b>Age:</b>
<input type="number" name="stu_age" value="<?= $row["stu_age"] ?>">
<br>
<b>Birthdate:</b>
<input type="" name="stu_birthdate" value="<?= $row["stu_birthdate"] ?>">
<br>
<b>Address:</b>
<input type="text" name="stu_address" value="<?= $row["stu_address"] ?>">
<br>
<button name="edit">Edit</button>
</form>
<?php
}
} else {
header("Location: index.php");
exit();
}