-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.php
53 lines (52 loc) · 2.25 KB
/
submit.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
<?php
require "connect.php";
if(isset($_POST['ldap']) && isset($_POST['hostel']) && isset($_POST['amount'])&&isset($_POST['agreeToConditon'])){
$ldap = $_POST['ldap'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$hostel = $_POST['hostel'];
$amount = $_POST['amount'];
$conditionAccepted = $_POST['agreeToConditon'] === '1'? 1: 0;
try{
$studentQuery = "SELECT * from covid19 where ldap=:ldap";
$studentStmt = $conn->prepare($studentQuery);
$studentStmt->execute(array("ldap"=>$ldap));
$results = $studentStmt->fetchAll(PDO::FETCH_ASSOC);
if(count($results)!=0){
// echo json_encode($results);
$stmt1 = "UPDATE covid19 SET amount=:amount, hostel=:hostel,conditionAccepted=:conditionAccepted WHERE ldap=:ldap";
$stmt = $conn->prepare($stmt1);
$stmt->bindParam(':ldap', $ldap, PDO::PARAM_STR, 1000);
$stmt->bindParam(':hostel', $hostel, PDO::PARAM_STR, 10);
$stmt->bindParam(':amount', $amount, PDO::PARAM_INT);
$stmt->bindParam(':conditionAccepted', $conditionAccepted, PDO::PARAM_BOOL);
$stmt->execute();
}else{
// echo json_encode(array("error"=>"No student found with that ldap"));
$stmt1 = "INSERT into covid19 (ldap,hostel,amount,first_name,last_name,conditionAccepted) VALUES (:ldap,:hostel,:amount,:first_name,:last_name,:conditionAccepted)";
$stmt = $conn->prepare($stmt1);
$stmt->bindParam(':ldap', $ldap, PDO::PARAM_STR, 1000);
$stmt->bindParam(':hostel', $hostel, PDO::PARAM_STR, 10);
$stmt->bindParam(':amount', $amount, PDO::PARAM_INT);
$stmt->bindParam(':first_name', $first_name, PDO::PARAM_STR, 1000);
$stmt->bindParam(':last_name', $last_name, PDO::PARAM_STR, 1000);
$stmt->bindParam(':conditionAccepted', $conditionAccepted, PDO::PARAM_BOOL);
$stmt->execute();
}
}catch(PDOException $e){
echo json_encode(array("error"=>$e->getMessage()));
}
}
function get_ldap_amount($ldap_id){
require "connect.php";
try{
$studentQuery = "SELECT * from covid19 where ldap=:ldap";
$studentStmt = $conn->prepare($studentQuery);
$studentStmt->execute(array("ldap"=>$ldap_id));
$results = $studentStmt->fetchAll(PDO::FETCH_ASSOC);
}catch(PDOException $e){
echo json_encode(array("error"=>$e->getMessage()));
}
return $results;
}
?>