• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

warning foreach()

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
Warning: Invalid argument supplied for foreach() in /var/www/html/pages/accountmanagement.php


help?

PHP:
foreach($data as $i => $ban)

                $kada1 = $ban['expires_at'] - time();
                $kada2 = date("i",$kada1);
                $kada3 = date("s",$kada1);
                $kada4 = $kada1/60/60;
                $kada4 = current(explode(".", $kada4));

                if($kada1 < 60)
                {
                $welcome_msg = "Welcome to your account!";
                }
                elseif($kada4 >= 1)
                {
                $welcome_msg = "<font color='red'>Your account is banished and will <b>expires in: $kada4 h, $kada2 min.</b></font>";
                }
                elseif($kada2 >= 1)
                {
                $welcome_msg = "<font color='red'>Your account is banished and will <b>expires in: $kada2 min, $kada3 sec.</b></font>";
                }
 
Solution
You need to put the whole code block in curly brackets - {}

Like this:
PHP:
if($account_logged->getBanTime() > 0)
                $welcome_msg = '<font color="red">Your account is banished until '.date("j F Y, G:i:s", $account_logged->getBanTime()).'!</font>';
            else {
                $data = $SQL->query('SELECT `players_data`.`name`, `account_bans`.`account_id`, `account_bans`.`reason`, `account_bans`.`banned_at`, `account_bans`.`expires_at`, `account_bans`.`banned_by` FROM `account_bans` INNER JOIN (SELECT * FROM (SELECT `account_id`, `name` FROM `players` WHERE `players`.`account_id` IN (SELECT `account_id` FROM `account_bans`) ORDER BY `level` DESC) x GROUP BY `account_id`) players_data ON `account_bans`.`account_id` =...
What is inside of $data variable? (some lines above)

PHP:
if($account_logged->getBanTime() > 0)
                $welcome_msg = '<font color="red">Your account is banished until '.date("j F Y, G:i:s", $account_logged->getBanTime()).'!</font>';
            else
                $data = $SQL->query('SELECT `players_data`.`name`, `account_bans`.`account_id`, `account_bans`.`reason`, `account_bans`.`banned_at`, `account_bans`.`expires_at`, `account_bans`.`banned_by` FROM `account_bans` INNER JOIN (SELECT * FROM (SELECT `account_id`, `name` FROM `players` WHERE `players`.`account_id` IN (SELECT `account_id` FROM `account_bans`) ORDER BY `level` DESC) x GROUP BY `account_id`) players_data ON `account_bans`.`account_id` = `players_data`.`account_id`')->fetchAll();
           
                foreach($data as $i => $ban)
 
You need to put the whole code block in curly brackets - {}

Like this:
PHP:
if($account_logged->getBanTime() > 0)
                $welcome_msg = '<font color="red">Your account is banished until '.date("j F Y, G:i:s", $account_logged->getBanTime()).'!</font>';
            else {
                $data = $SQL->query('SELECT `players_data`.`name`, `account_bans`.`account_id`, `account_bans`.`reason`, `account_bans`.`banned_at`, `account_bans`.`expires_at`, `account_bans`.`banned_by` FROM `account_bans` INNER JOIN (SELECT * FROM (SELECT `account_id`, `name` FROM `players` WHERE `players`.`account_id` IN (SELECT `account_id` FROM `account_bans`) ORDER BY `level` DESC) x GROUP BY `account_id`) players_data ON `account_bans`.`account_id` = `players_data`.`account_id`')->fetchAll();
          
                foreach($data as $i => $ban)
                    $kada1 = $ban['expires_at'] - time();
                $kada2 = date("i",$kada1);
                $kada3 = date("s",$kada1);
                $kada4 = $kada1/60/60;
                $kada4 = current(explode(".", $kada4));

                if($kada1 < 60)
                {
                $welcome_msg = "Welcome to your account!";
                }
                elseif($kada4 >= 1)
                {
                $welcome_msg = "<font color='red'>Your account is banished and will <b>expires in: $kada4 h, $kada2 min.</b></font>";
                }
                elseif($kada2 >= 1)
                {
                $welcome_msg = "<font color='red'>Your account is banished and will <b>expires in: $kada2 min, $kada3 sec.</b></font>";
                }
}

Otherwise, the $data variable won't be defined in some cases (when $account_logged->getBanTime() > 0).
 
Solution
Back
Top