I genuinely do not understand how this code is messing up but it just is, I've never ran into anything of the sort so if anyone can explain what is going on i'd be very glad.
The code : $functions->update("batzz",$functions->getPlayerInfo("batzz"));
runs no matter whether the if condition is met or not, which is starting to get very frustrating.
This is the whole excerpt of code. There is no loop around it, and when it runs, it prints the proper statement but regardless of whether the if is true or false, it runs the update function.
if($functions->checkRecordsExist($_GET['name']) == false) {
$functions->update("batzz",$functions->getPlayerInfo("batzz"));
echo "Your account has been updated! Visit your page <a href='/osrstracker/name/". $_GET['name'] ."'>here</a>";
} else {
echo "Oops, either you havess already updated your account within the past 12 hours or we have messed something up!";
}
I would love to understand how this possibly could happen, and if I can fix it as it is very annoying!
Code for function : $functions->checkRecordsExist($_GET['name']) == false
public function checkRecordsExist($dpname){
$curdate = date("Y-m-d H:i:s");
$olddate = date('Y-m-d H:i:s', strtotime('-12 hour'));
$this->query("SELECT * FROM stats JOIN accounts ON stats.userid = accounts.id WHERE accounts.displayName=:dpname AND stats.date BETWEEN '$olddate' AND '$curdate';");
$this->bind(":dpname",$dpname);
$result = $this->resultSet();
if(!empty($result)){
if($result[0]['rank'] == 1){
$this->query("SELECT * FROM stats JOIN accounts ON stats.userid = accounts.id WHERE accounts.displayName=:dpname AND stats.date BETWEEN '$olddate' AND '$curdate';");
$this->bind(":dpname",$dpname);
$result2 = $this->resultSet();
if(empty($result2)){
return false;
}
}
return true;
}
return false;
}
PDO Object after query being prepared
object(PDOStatement)#3 (1) {
["queryString"]=>
string(171) "SELECT * FROM stats JOIN accounts ON stats.userid = accounts.id WHERE accounts.displayName=:dpname AND stats.date BETWEEN '2016-03-19 11:48:36' AND '2016-03-19 23:48:36';"
}