forked from reed-jones/minesweeper_js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddHighScores_example.php
More file actions
35 lines (29 loc) · 919 Bytes
/
Copy pathaddHighScores_example.php
File metadata and controls
35 lines (29 loc) · 919 Bytes
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
<?php
//Connect to DB
require("../connect.php");
$name = $_POST['n'];
$time = intval($_POST['t']);
$difficulty = intval($_POST['d']);
if ($name === NULL || $time === NULL || $difficulty === NULL){
exit();
//exit("null values found");
}
if (is_nan($time) || !is_numeric($time) || $time < 0){
exit();
//exit("invalid difficulty");
}
if (is_nan($difficulty) || $difficulty > 2 || $difficulty < 0){
exit();
//exit("invalid difficulty");
}
// set default name if no name was supplied
if($name == "") {
$name = "Unknown";
}
// if name is too long for the database, only grab the first 25 letters (since database limit is a varchar(25))
$name = substr($name, 0, 25);
// Prepare a query for execution
$result = pg_prepare($con, "my_query", 'INSERT INTO _Table_(name, time, difficulty) VALUES($1,$2,$3)');
// Execute the prepared query.
$result = pg_execute($con, "my_query", array($name, $time, $difficulty));
?>