friend
friend

Reputation: 19

MySQLi display to PHP code

My issue is that I cant login with this because for some reason it dont let me, if I have the code getting the data from the database it dont work (I have a clear connection and connects just fine)

    <?php
$steamauth['apikey'] = APIKEY; // Your Steam WebAPI-Key found at http://steamcommunity.com/dev/apikey
$steamauth['domainname'] = WEBSITE; // The main URL of your website displayed in the login page
$steamauth['logoutpage'] = WEBSITE; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = WEBSITE; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}

$steamid=mysqli_connect("","","","");
$steamid->set_charset("utf8");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($steamid, "SELECT * FROM panel_admins");

if (!$result) {
    printf("Error: %s\n", mysqli_error($steamid));
    exit();
}

echo "";

while ($row = mysqli_fetch_array($result)) {

$allowed_ids = [
    '"' . $row['steamid'] . '"',
];

}

mysqli_close($steamid);
?>

But on the other hand if I have my code like this, I can login with no problem

<?php
$steamauth['apikey'] = APIKEY; // Your Steam WebAPI-Key found at http://steamcommunity.com/dev/apikey
$steamauth['domainname'] = WEBSITE; // The main URL of your website displayed in the login page
$steamauth['logoutpage'] = WEBSITE; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = WEBSITE; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}

// allow only these ids
$allowed_ids = [
    'steamid64here',
];
?>

Maybe the code is not good or something. Im using PHP 5.6! What I want with this code? I want to in the steamid column it will grab the steamid64 and put there.

Upvotes: 0

Views: 62

Answers (1)

Ketan Yekale
Ketan Yekale

Reputation: 2213

You are overwriting the value of $allowed_ids in while loop in each pass.

Try the code below:

   $allowed_ids = array(); // initializing array
   while ($row = mysqli_fetch_array($result)) {
         $allowed_ids[] = $row['steamid'] ;// inserting elements into the array
   }

Upvotes: 1

Related Questions