-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteachinglearning_save.php
More file actions
68 lines (56 loc) · 2.22 KB
/
teachinglearning_save.php
File metadata and controls
68 lines (56 loc) · 2.22 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
<?php
$db = new MySqli('localhost', 'root', '', 'pbas_db');
?>
<?php
$action = (!empty($_POST['action'])) ? $_POST['action'] : ''; //action to be used(insert, delete, update, fetch)
$lstparray = (!empty($_POST['lstparray'])) ? $_POST['lstparray'] : ''; //an array of the student details
//check if the student is not an empty string
//and assigns a value to $name and $age if its not empty
if(!empty($lstparray)){
$course = $lstparray['course'];
$level = $lstparray['level'];
$mot = $lstparray['mot'];
$noc = $lstparray['noc'];
$practicals = $lstparray['practicals'];
$ctdr = $lstparray['ctdr'];
$ctapi = $lstparray['ctapi'];
$tlapi = $lstparray['tlapi'];
}
switch($action){
default:
//only select student records which aren't deleted
$students = $db->query("SELECT * FROM teach_lstp");
$students_r = array();
while($row = $students->fetch_array()){
//default student data
$course = $row['Teach_LSTP_Course'];
$level = $row['Teach_LSTP_Level'];
$mot = $row['Teach_LSTP_MOT'];
$noca = $row['Teach_LSTP_NOCA'];
$nocc = $row['Teach_LSTP_NOCC'];
$practicals = $row['Teach_LSTP_Practicals'];
$ctdr = $row['Teach_LSTP_CTDR'];
$ctapi = $row['Teach_LSTP_CTAPI'];
$tlapi = $row['Teach_LSTP_TLAPI'];
//build the array that will store all the student records
$students_r[] = array(
'id' => $id, 'name' => $name, 'age' => $age,
'nameUpdate' => $name_update, 'ageUpdate' => $age_update,
);
}
echo json_encode($students_r); //convert the array to JSON string
break;
case 'insert':
$db->query("INSERT INTO teach_lstp SET Teach_LSTP_Course = '$course', Teach_LSTP_Level = '$level', Teach_LSTP_MOT='$mot', Teach_LSTP_NOCA='$noca' , Teach_LSTP_NOCC='$nocc' , Teach_LSTP_Practicals='$practicals' , Teach_LSTP_CTDR='$ctdr' , Teach_LSTP_CTAPI='$ctapi' , Teach_LSTP_TLAPI='$tlapi' ");
echo $db->insert_id; //last insert id
break;
case 'update':
$id = $student['id'];
$db->query("UPDATE students SET name = '$name', age = '$age' WHERE id = '$id'");
break;
case 'delete':
$id = $_POST['student_id'];
$db->query("UPDATE students SET status = '0' WHERE id = '$id'");
break;
}
?>