From 2f7e4fed5d9bf2c0eb4f7ba4218003a89de43ecf Mon Sep 17 00:00:00 2001 From: jundis Date: Tue, 30 Jan 2018 15:51:14 -0600 Subject: [PATCH] Fix for users not being created for stats --- cwslack-stats.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cwslack-stats.php b/cwslack-stats.php index 634cba9..c80ef81 100644 --- a/cwslack-stats.php +++ b/cwslack-stats.php @@ -5,6 +5,9 @@ * Date: 10/26/2017 * Time: 9:40 AM */ +ini_set('display_errors', 1); +include 'config.php'; +$debugmode = true; $mysql = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbdatabase); //Connect MySQL @@ -24,7 +27,6 @@ } else { echo "stats Table Creation Error: " . mysqli_error($mysql); } - $statscommand = substr($_REQUEST['command'],1); $statsuser = $_REQUEST['user_name']; @@ -43,17 +45,20 @@ die("MySQL Error: " . mysqli_error($mysql)); } } - $statsdate = date("Y-m-d H:i:s"); $sql = "SELECT * FROM `stats` WHERE `user` = '" . $statsuser . "'"; //SQL Query to select all users $result = mysqli_query($mysql, $sql); //Run result -if($result) // If query worked +$rowcount = mysqli_num_rows($result); +if($rowcount > 1) //If there were too many rows matching query +{ + die("Error: too many users somehow?"); //This should NEVER happen. +} +else if ($rowcount == 1) //If exactly 1 row is found. { $statsuserdata = mysqli_fetch_assoc($result); $commandcount = $statsuserdata[$statscommand] + 1; $sql = "UPDATE `stats` SET lastcommand = '" . $statscommand . "', lastused = '" . $statsdate . "', " . $statscommand ." = '" . $commandcount . "' WHERE `user` = '" . $statsuser . "'"; //SQL Query to insert new map - if(mysqli_query($mysql,$sql)) { // Inserted user @@ -66,7 +71,6 @@ else { $sql = "INSERT INTO `stats` (`user`, `lastcommand`, `lastused`, `" . $statscommand . "`) VALUES ('" . $statsuser . "', '" . $statscommand . "', '" . $statsdate . "', 1);"; //SQL Query to insert new map - if(mysqli_query($mysql,$sql)) { // Inserted user @@ -78,5 +82,4 @@ } - ?> \ No newline at end of file