-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_score.php
50 lines (38 loc) · 1.05 KB
/
save_score.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
<?php
error_reporting(0);
if(!$_POST){
return false;
}
save_score();
function save_score(){
$type = $_POST['type'];
$percentage = $_POST['per'];
$total_q = $_POST['total'];
$correct_q = $_POST['correct'];
$incorrect_q = $_POST['incorrect'];
$na_q = $_POST['na'];
$time = $_POST['time'];
$speed = $_POST['speed'];
$remark = $_POST['remark'];
$output = array();
$mysqli = new mysqli('localhost','root','','gre') ;
try {
if (mysqli_connect_errno()){
throw new exception ("Error: Could not connnect to mysql db");
}
$sql = "INSERT INTO quiz_score
(id, `type`, percentage, total_q, correct_q, incorrect_q, na_q, time, speed, updated,remark)
VALUES (NULL, '$type', '$percentage', '$total_q', '$correct_q', '$incorrect_q', '$na_q', '$time', '$speed', NOW(),'$remark')";
$db = $mysqli->query($sql);
if($db){
throw new exception ( "Data Saved Successfully");
}else{
throw new exception ( "Could not save data,check your query") ;
}
}
catch (exception $e) {
echo json_encode($e->getmessage());
$mysqli->close();
return false;
}
}