Skip to content

Commit

Permalink
Added ` quotation marks for non-value SQL words.
Browse files Browse the repository at this point in the history
This fixes some problems when SQL queries don't run correctly.
  • Loading branch information
darrensapalo committed Dec 19, 2018
1 parent cdfa55f commit 76f456f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/voteforpoints/function.php
Expand Up @@ -8,7 +8,7 @@ function isChanged($id, $col, $row, $server)
{
$vfp_sites = Flux::config('FluxTables.vfp_sites');

$sql = "SELECT * FROM $server->loginDatabase.$vfp_sites WHERE $col = ? AND id = ?";
$sql = "SELECT * FROM `$server->loginDatabase.$vfp_sites` WHERE `$col` = ? AND `id` = ?";
$sth = $server->connection->getStatement($sql);
$bind = array($row, (int) $id);
$sth->execute($bind);
Expand All @@ -26,7 +26,7 @@ function updateValue($id, $col, $row, $server)
{
$vfp_sites = Flux::config('FluxTables.vfp_sites');

$sql = "UPDATE $server->loginDatabase.$vfp_sites SET $col = ? WHERE id = ?";
$sql = "UPDATE `$server->loginDatabase.$vfp_sites` SET `$col` = ? WHERE `id` = ?";
$sth = $server->connection->getStatement($sql);
$bind = array($row, (int) $id);
$sth->execute($bind);
Expand All @@ -49,7 +49,7 @@ function isVoted($id, $server)

if (Flux::config('EnableIPVoteCheck'))
{
$sql = "SELECT timestamp_expire FROM $server->loginDatabase.$vfp_logs WHERE ipaddress = ? AND sites_id = ? AND UNIX_TIMESTAMP(timestamp_expire) > ? LIMIT 1";
$sql = "SELECT `timestamp_expire` FROM `$server->loginDatabase.$vfp_logs` WHERE `ipaddress` = ? AND `sites_id` = ? AND UNIX_TIMESTAMP(timestamp_expire) > ? LIMIT 1";
$sth = $server->connection->getStatement($sql);
$bind = array($ipaddress, $vote_id, time());
$sth->execute($bind);
Expand All @@ -58,7 +58,7 @@ function isVoted($id, $server)
return $sth->fetch()->timestamp_expire;
}

$sql = "SELECT timestamp_expire FROM $server->loginDatabase.$vfp_logs WHERE account_id = ? AND sites_id = ? AND UNIX_TIMESTAMP(timestamp_expire) > ? LIMIT 1";
$sql = "SELECT `timestamp_expire` FROM `$server->loginDatabase.$vfp_logs` WHERE `account_id` = ? AND `sites_id` = ? AND UNIX_TIMESTAMP(timestamp_expire) > ? LIMIT 1";
$sth = $server->connection->getStatement($sql);
$bind = array($account_id, $vote_id, time());
$sth->execute($bind);
Expand All @@ -75,7 +75,7 @@ function isVoted($id, $server)
function getCashPoints($account_id, $server)
{
$cp_tbl = Flux::config('FluxTables.cashpoints');
$sql = "SELECT value FROM $cp_tbl WHERE account_id = ? AND key = '#CASHPOINTS'";
$sql = "SELECT `value` FROM `$cp_tbl` WHERE `account_id` = ? AND `key` = '#CASHPOINTS'";
$sth = $server->connection->getStatement($sql);
$sth->execute(array((int) $account_id));

Expand Down Expand Up @@ -122,4 +122,4 @@ function getTimeLeft($ts)
}
}

?>
?>

2 comments on commit 76f456f

@darrensapalo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please feel free to use your native language. I will use Google translate.

And I think your problem is that it says ragnarok main.ragnarok_main it is not supposed to repeat. Check your configuration for vote 4 points. See if the tables are correct.

@darrensapalo
Copy link
Owner Author

@darrensapalo darrensapalo commented on 76f456f Mar 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Haikenz Hi there. Would you mind exporting your database (minus sensitive data) and forking your FluxCP so I can take a look? Hope you've fixed it somehow by now.

Suggestion

Try executing the following code right before the SQL query execution where $sql is your SQL query, to see if the SQL is being formed correctly:

$sql = '....';
die($sql);

// ...
$sth = $server->connection->getStatement($sql);
$sth->execute(array((int) $account_id));

Where do I put this code?

To find out where exactly you need to put this, look for error number 3 on the PHP source code.

The critical clue to your bug is the repeated ragnarok main.ragnarok_main table name. So try to follow on that clue as to why your query fails.

Please sign in to comment.