-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreSubmission.php
65 lines (48 loc) · 1.89 KB
/
ScoreSubmission.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
<?php
$servername = "localhost";
$username = "niranjan";
$password = "anandam";
$dbname = "MemoryControl";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST['name'];
$email = $_POST['email'];
$score = $_POST['gameScore'];
$sql = "INSERT INTO MemoryGameStats (id, name, email, score)
VALUES ('memory game', '" . $name . "', '" . $email . "', " . $score . ")";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
<script type="text/javascript" src="JS/jquery.min.js"></script>
<script type="text/javascript">
var highScore, currentPosition, score = "<?php echo $score; ?>";
$.get("returnMaxScore.php", function (data) {
if (data != undefined) {
highScore = data[0]["MAX_SCORE"];
$.get("returnCurrrentPosition.php?Score=" + score + "", function (data) {
if (data != undefined) {
currentPosition = data[0]["CURRENT_POSITION"];
document.write("<h1 style='text-align:center'>Thanks for playing and enjoying Game<h1>");
document.write("<h2 style='text-align:center'>High Score : " + highScore + "<h2>");
document.write("<h2 style='text-align:center'>Your Score :" + score + "<h2>");
document.write("<h2 style='text-align:center'>Your Rank: " + (parseInt(currentPosition) + 1) + "<h2>");
document.write("<h2 style='text-align:center'><a href='MemoryGame.html'>Do you want to play again</a><h2>");
}
else {
document.write("error conntecting to Database");
}
});
}
else {
document.write("error conntecting to Database");
}
});
</script>