-
Notifications
You must be signed in to change notification settings - Fork 4
/
createcourse.php
79 lines (67 loc) · 1.76 KB
/
createcourse.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
<?php
error_reporting(0);
//Database Connection
define('INCLUDE_CHECK', true);
require 'connect.php';
//json decode the values recieved
$_POST = json_decode(file_get_contents('php://input'), true);
//Params passed or not
if(!isset($_POST['courseName'])){
$output = array(
"status" => false,
"error" => "Course Name is not set is not set",
"errorCode" => "102",
"response" => ""
);
die(json_encode($output));
}
if(!isset($_POST['courseCode'])){
$output = array(
"status" => false,
"error" => "course code is not set",
"errorCode" => "102",
"response" => ""
);
die(json_encode($output));
}
if(!isset($_POST['subjectCode'])){
$output = array(
"status" => false,
"error" => "division is not set",
"errorCode" => "102",
"response" => ""
);
die(json_encode($output));
}
//assign the values to local varibles
$courseName=$_POST['courseName'];
$courseCode=$_POST['courseCode'];
$subjectCode=$_POST['subjectCode'];
//check if the subject already exists
$clash = false;
$course=mysql_query("SELECT `courseName`, `courseCode`, `subjectCode` FROM `dash_course` WHERE `courseName`='{$courseName}' AND `courseCode`='{$courseCode}'");
while($row = mysql_fetch_assoc($course)){
$clash=true;
$output = array(
"status" => false,
"error" => "This particular course already Exists",
"errorCode" => "201",
"response" => ""
);
die(json_encode($output));
}
//if new subject add to database
if(!$clash){
mysql_query("INSERT INTO `dash_course`(`courseName`, `courseCode`, `subjectCode`) VALUES ('{$courseName}','{$courseCode}','{$subjectCode}')");
$response = array(
"message" => "course was created sucessfully"
);
$output = array(
"status" => true,
"error" => "",
"errorCode" => "",
"response" => $response
);
echo json_encode($output);
}
?>