-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.php
47 lines (39 loc) · 1.29 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
<?php
include "db_connection.php";
if(isset($_POST["submitBtn"]) && $_POST["submitBtn"]!=""){
$name = $_POST["name"];
$score = $_COOKIE['highscore'];
$scoring = (int)$score;
$sql1 = "INSERT INTO Scores(name, score) VALUES(:name, :scoring)";
$stmt = $pdo->prepare($sql1);
$stmt->execute([
':name' => $name,
':scoring' => $scoring,
]);
};
?>
<head>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="css/mathtrainer.css" />
<a id="leaderboard" href="leaderboard.php">Leaderboard</a>
</head>
<Body>
<h1> Congratulations <?php echo $name; ?>!!!</h1>
<h2> Your scored of <?php echo $scoring; ?> has been submitted!</h2>
<?php
$sql3 = "SELECT * from Scores WHERE score > :score";
$stmt3 = $pdo->prepare($sql3);
$stmt3->execute([
':score' => $scoring,
]);
$count2 = $stmt3->rowCount();
$sql4 = "SELECT * FROM Scores";
$stmt4 = $pdo->prepare($sql4);
$stmt4->execute([]);
$total = $stmt4->rowCount();
$percent = (float)($count2 / $total) * 100;
$userPercent = round($percent, 1);
?>
<h2> You placed in the top <?php echo $userPercent; ?>%</h2>