While looking through stackoverflow I found the following: How to create a dynamic PHP switch statement from MySQL query
Which resulted in me trying something I haven't before, it doesn't work, but I am curious as to why it doesn't work rather than trying to figure out a way to make it work.
Here's my code:
function SOMENAME(){
global $mysqli ;
$out = false ;
$VALIDTOKENS = array();
$sql = "SELECT * FROM `tokens` ORDER BY `tokens`.`id` ASC";
if($result = mysqli_query($mysqli, $sql)) {
while ($row = mysqli_fetch_assoc($result)) {
$VALIDTOKENS[$row['token']] = $row['token'];
}
}
if(isset($_GET['key'])) {
$key = $_GET['key'];
}
switch($key) {
case $VALIDTOKENS[$key]:
$out = true ;
break;
}
return $out ;
}
The function always returns false.