-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreatesubject.php
67 lines (57 loc) · 1.46 KB
/
createsubject.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
<?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['subjectName'])){
$output = array(
"status" => false,
"error" => "std 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
$subjectName=$_POST['subjectName'];
$subjectCode=$_POST['subjectCode'];
//check if the subject already exists
$clash = false;
$subject=mysql_query("SELECT `subjectName`, `subjectCode` FROM `dash_subject` WHERE `subjectCode`= '{$subjectCode}'");
while($row = mysql_fetch_assoc($subject)){
$clash=true;
$output = array(
"status" => false,
"error" => "This particular subject already Exists",
"errorCode" => "201",
"response" => ""
);
die(json_encode($output));
}
//if new subject add to database
if(!$clash){
mysql_query("INSERT INTO `dash_subject`(`subjectName`, `subjectCode`) VALUES ('{$subjectName}','{$subjectCode}')");
$response = array(
"message" => "subject was created sucessfully"
);
$output = array(
"status" => true,
"error" => "",
"errorCode" => "",
"response" => $response
);
echo json_encode($output);
}
?>