-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
90 lines (75 loc) · 1.98 KB
/
update.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
include 'connection.php';
require 'class/class.php';
$conn = connection();
$sel=new student;
$s3lect= $sel->details($_GET['id'],$conn);
//print_r($s3lect);
if(empty($s3lect)){
echo "</br>invalie user id";
}
else{
$id=$s3lect['0']['id'];
$name=$s3lect['0']['name'];
$age=$s3lect['0']['age'];
$designation=$s3lect['0']['designation'];
if(!empty($_POST)){
if(empty($_POST['id'])){
$error_arr['id']="Empty Id";
}
else{
$id=$_POST['id'];
}
if(empty($_POST['name'])){
$error_arr['name']="Empty name";
}
else{
$name=$_POST['name'];
}
if(empty($_POST['age'])){
$error_arr['age']="Empty age";
}
else{
$age=$_POST['age'];
}
if(empty($_POST['designation'])){
$error_arr['designation']="Empty designation";
}
else{
$designation=$_POST['designation'];
}
if(empty($error_arr)){
$upd_id=$_GET['id'];
$sql="update student set id=$id,name='".$name."',age=$age,designation='".$designation."' where id=$upd_id";
if(mysqli_query($conn, $sql)){
echo "updated successfully";
header('location:view.php');exit;
}
else{
echo "not updated properly".mysqli_error($conn);
}
}
}
else{
echo ("form not edited");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add</title>
</head>
<body>
<form name="db" method="POST" action="">
<?php if(!empty($error_arr)){ foreach ($error_arr as $err_value) {
echo "<p class style='color:red'>".$err_value."</p>";
}}?>
id:<input type="text" name="id" id="id" value="<?php if(!empty($id)){echo $id;}?>"><br>
name:<input type="text" name="name" id="name" value="<?php if(!empty($name)){echo $name;}?>"><br>
age:<input type="text" name="age" id="age" value="<?php if(!empty($age)){echo $age;}?>"><br>
designation:<input type="text" name="designation" id="designation" value="<?php if(!empty($designation)){echo $designation;}?>"><br>
<input type="submit" name="submit" id="submit" value="submit">
</form>
</body>
</html>
<?}?>