-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave.php
43 lines (33 loc) · 1.12 KB
/
save.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
<?php
require('config.php');
/**
* This file contains the api calls for database connections etc
*
*/
$result = array();
// Check for AJAX
if ( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) {
// Make safe!
$player = mysql_real_escape_string($_REQUEST["player"]);
$score = mysql_real_escape_string($_REQUEST["score"]);
$created = date('Y-m-d H:i:s', time('now'));
// Prep the database
$link = mysql_connect($db['host'], $db['user'], $db['password']);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db['database']);
// Insert
mysql_query("INSERT INTO scores (player, score, created) values ('$player', '$score', '$created')");
// printf("Last inserted record has id %d\n", mysql_insert_id());
$result['status'] = TRUE;
$result['playerId'] = mysql_insert_id();
$result['message'] = "Record successfully inserted";
// TODO: return top scores
} else {
$result['status'] = FALSE;
$result['message'] = 'Only XML request allowed';
}
// Return the status
header('Content-type: application/json');
echo json_encode($result);