0

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.

1 Answers1

0

From the logic of your code,when it returns false, there are many possibilities, such as the database failed to link, the query failed, the database table does not exist, the field does not exist, etc. You are advised to debug with breakpoints, you can use var_dump() in different lines of code, check the returned results.