Skip to content

Commit

Permalink
🔧Modify SQL statement
Browse files Browse the repository at this point in the history
  • Loading branch information
arcxingye committed Apr 20, 2022
1 parent 5100854 commit ec046f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
5 changes: 2 additions & 3 deletions SubmitResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
define('TIME_LIMIT', 5);
$time = time();
if (isset($_SESSION['time'])) {
if ($time - $_SESSION['time'] <= TIME_LIMIT)
{
if ($time - $_SESSION['time'] <= TIME_LIMIT) {
echo 'Only 1 upload in 5 seconds';
exit();
}
Expand All @@ -28,7 +27,7 @@

if ((!empty($name)) && (strlen($name) <= 30) && (strlen($system) <= 30) && (strlen($area) <= 30) && (strlen($message) <= 150) && (is_numeric($score)) && ($score < 300) && ($t == $_SESSION['t'])) {
@require 'conn.php';
$score_sql = "SELECT `score`,`attempts` FROM " . $ranking . " WHERE `name`=?";
$score_sql = "SELECT `score`,`attempts` FROM " . $ranking . " WHERE `name`=?";
$score_stmt = $link->prepare($score_sql);
$score_stmt->bind_param("s", $name);
$score_stmt->bind_result($highest, $attempts);
Expand Down
15 changes: 8 additions & 7 deletions rank.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
if ($RankingType == 'query') {
$queryname = isset($_GET['query']) ? $_GET['query'] : '';
$title = $i18n['query-record'];
$cond1 = "where name=?";
$cond1 = "WHERE `name` LIKE ?";
$cond2 = $cond1 . ";";
}
if ($RankingType == 'day') {
$title = $i18n['day-rank'];
$cond1 = "where to_days(time) = to_days(now())";
$cond2 = $cond1 . " ORDER BY score DESC limit ?,?;";
$cond1 = "WHERE to_days(time) = to_days(now())";
$cond2 = $cond1 . " ORDER BY `score` DESC limit ?,?;";
}
if ($RankingType == 'week') {
$title = $i18n['week-rank'];
$cond1 = "where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(time)";
$cond2 = $cond1 . " ORDER BY score DESC limit ?,?;";
$cond1 = "WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(time)";
$cond2 = $cond1 . " ORDER BY `score` DESC limit ?,?;";
}
if ($RankingType == 'month') {
$title = $i18n['month-rank'];
$cond1 = "where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(time)";
$cond2 = $cond1 . " ORDER BY score DESC limit ?,?;";
$cond1 = "WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(time)";
$cond2 = $cond1 . " ORDER BY `score` DESC limit ?,?;";
}
if ($RankingType == 'all') {
$title = $i18n['all-rank'];
Expand Down Expand Up @@ -112,6 +112,7 @@ function local() {
$data_sql = "SELECT * FROM " . $ranking . " " . $cond2;
if ($data_stmt = $link->prepare($data_sql)) {
if ($RankingType == "query") {
$queryname = '%'.$queryname.'%';
$data_stmt->bind_param("s", $queryname);
} else {
$data_stmt->bind_param("ii", $offset, $num);
Expand Down

0 comments on commit ec046f0

Please sign in to comment.