-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd-student.php
More file actions
33 lines (28 loc) · 849 Bytes
/
add-student.php
File metadata and controls
33 lines (28 loc) · 849 Bytes
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
<?php
include_once('./functions.php');
if(isset($_POST['save'])){
// process submitted data
// receive data
$first_name = isset($_POST['first_name']) ? $_POST['first_name'] : '';
$last_name = isset($_POST['last_name']) ? $_POST['last_name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$dob = isset($_POST['dob']) ? $_POST['dob'] : '';
// validate data
// TODO: validate and escape quotes
// process data
$insert = "insert into students set
first_name='$first_name',
last_name='$last_name',
email='$email',
dob='$dob'
";
$link = db_connect();
$res = mysqli_query($link, $insert);
if(!$res){
echo mysqli_error($link);
}else{
echo "Student successfully added. <a href=\"mysql.php\">Back to students list</a>";
}
}else{
echo load_view('./views/new-student.php');
}