-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
152 lines (123 loc) · 4.65 KB
/
index.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
require_once('inc/functions.php');
$task = $_GET['task'] ?? 'report';
$info = '';
if('seed' == $task){
seed();
$info = "Seeding is compleete";
}
/**
*
* Declare a variable like $fname $lname $roll
* when user update a form, it's save our db, but if any error it's also stay
*/
$fname = "";
$lname = "";
$roll = "";
if(isset($_POST['submit'])){
$fname = htmlspecialchars(filter_input(INPUT_POST, 'fname'));
$lname= htmlspecialchars(filter_input(INPUT_POST, 'lname'));
$roll = htmlspecialchars(filter_input(INPUT_POST, 'roll'));
$id = htmlspecialchars(filter_input(INPUT_POST, 'id'));
if($id){
if($fname != "" && $lname != "" && $roll != ""){
$result = updateStudent($id, $fname, $lname, $roll);
if(!$result){
$info = "Student Update successfully";
} else{
$info = "Same Roll already exists!!!";
}
}
} else{
if($fname != "" && $lname != "" && $roll != ""){
$result = addStudent($fname, $lname, $roll);
if(!$result){
$info = "Same ID already exists!!!";
} else{
$info = "Student added successfully";
}
} else {
$info = "Please fill all the fields";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LWHH CRUD Project</title>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
<style>
body {
margin-top: 30px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="column column-60 column-offset-20">
<h2>LWHH CRUD Project</h2>
<p>A sample project to perform CRUD operations using plain files and PHP</p>
<?php include_once('inc/templates/nav.php'); ?>
<hr/>
<?php
if($info != ''){
echo "<blockquote>{$info}</blockquote>";
}
?>
</div>
</div>
<?php if('report' == $task){ ?>
<div class="container">
<div class="row">
<div class="column">
<?php generateReport(); ?>
</div>
</div>
</div>
<?php } ?>
<?php if('add' == $task){ ?>
<div class="container">
<div class="row">
<div class="column column-60 column-offset-20">
<form method="POST">
<label for="fname">First Name</label>
<input type="text" name="fname" id="fname" value="<?php echo $fname; ?>">
<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname" value="<?php echo $lname; ?>">
<label for="roll">Roll</label>
<input type="number" name="roll" id="roll" value="<?php echo $roll; ?>">
<button type="submit" class="button-primary" name="submit">Save</button>
</form>
</div>
</div>
</div>
<?php } ?>
<?php if('edit' == $task){
$id = $_GET['id'];
$student = getStudent($id);
if($student){
?>
<div class="container">
<div class="row">
<div class="column column-60 column-offset-20">
<form method="POST">
<input type="hidden" name="id" value="<?php echo $student['id']; ?>">
<label for="fname">First Name</label>
<input type="text" name="fname" id="fname" value="<?php echo $student['fname']; ?>">
<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname" value="<?php echo $student['lname']; ?>">
<label for="roll">Roll</label>
<input type="number" name="roll" id="roll" value="<?php echo $student['roll']; ?>">
<button type="submit" class="button-primary" name="submit">Update</button>
</form>
</div>
</div>
</div>
<?php }} ?>
</body>
</html>