0

I have a xampp website with a little game in it, after reinstalling my pc the game wont work after login.

Basicly the login works perfeclty but at this parts its failing:

if($datauser[0]['factionid'] == 0)
{
    header('Location: company.php');
    exit();
}

At this point its redirecing me to the company.php but my factionid = 1 and when i remove it, it shows me that the Offset 0 is undefined. Basicly it cannot load my user information.

This is the $datauser information request.

include 'libs/database.php';
include 'config/database.php';

$db = new Database(DB_TYPE, DB_HOST, DB_NAME, DB_USER, DB_PASS);

$sth = $conn->prepare("SELECT username, is_admin , grade, factionid, clanid, credits, uridium, unobtanium, premium_time, vip_time, rankpoints, user_kill, npc_kill, max_hp, speed, damages, 
max_shield, drones, apis_built, zeus_built, laser_count, shield_count, speed_count, logfiles, booty_keys, drone_parts, skilltree, booster_dmg_time,
booster_shd_time, booster_spd_time, booster_npc_time, shipId, undermaintenance
FROM users WHERE id = :id LIMIT 1"); 
$sth->execute(array(
                ':id' => $_SESSION['player_id']
            ));
$datauser = $sth->fetchAll();

now i hope i explained enought and someone can help me. Ill be there for any questions or more code to awnser.

EDIT#1: its working perfectly on my remote server with IIS, but not on my XAMPP local server.

EDIT#2: its working if ill change prepare statement to:

$sth = $db->prepare("SELECT * FROM users WHERE id = :id LIMIT 1"); 

so why is it working with the * but not with all my values?

EDIT#3: FOUND THE SOLUTION, i searched for the value of "undermaintenance" but it was missing in my local database. Thanks everyone who helped me.

Greetings, Kevin

Kevin Becker
  • 21
  • 1
  • 4
  • If that query fills `$datauser`, and `$datauser[0]` is undefined, then whatever `player_id` is in your session (if there is anything there at all) does not refer to an existing user id – rickdenhaan Nov 25 '18 at 00:02
  • thx for your reply but my problem is, that this system is working perfeclty on my remote server, but not on my XAMPP local server – Kevin Becker Nov 25 '18 at 00:09
  • Are both servers running the same version of PHP and do they have the same database? A quick check could be for you to, on your local server, output the value of `$_SESSION['player_id']` and then check your (I assume also local) database to see if there's a matching user in it. – rickdenhaan Nov 25 '18 at 00:12
  • checking the $_SESSION['player_id'] gives back the value 1, same as my user id should be – Kevin Becker Nov 25 '18 at 00:15
  • Sounds like you should look at getting your error reporting correctly. You should have got an error about an unknown column. – user3783243 Nov 25 '18 at 00:49
  • yes, probably because its my local server only... i had everything setup perfectly before resetting my pc. Thank you anyways – Kevin Becker Nov 25 '18 at 00:56
  • Are you using version control, or anything so your environments are consistent? You want both to throw notices/errors the same way. Don't display your notices/errors though (or at the very least not in production), just log them. – user3783243 Nov 25 '18 at 03:25

1 Answers1

0

To remove notice, you need to check the array offset:

if(isset($datauser[0]['factionid']) && $datauser[0]['factionid'] == 0)

Also check the fetch result into $datauser by var_dump($datauser); or print_r($datauser);

TARiK
  • 16
  • 1
  • thx for your reply but my problem is, that this system is working perfeclty on my remote server, but not on my XAMPP local server - there must be any issue with xampp i guess – Kevin Becker Nov 25 '18 at 00:09
  • Check the $_SESSION['player_id'] value. May be session was not started. Or you have some troubles with cookies. – TARiK Nov 25 '18 at 00:15
  • $_SESSION['player_id'] gives back the value 1, same as my user id should be – Kevin Becker Nov 25 '18 at 00:16
  • var_dump($datauser); = array(0) { } – Kevin Becker Nov 25 '18 at 00:23
  • FYI: i found out what was wrong. In my request of the datauser was a mistake. It tries to load: speed, damages, max_shield but these three arent existing anymore, because i deleted them. If i change it to SELECT * FROM users WHER ... it works perfectly. so i guess IIS is just saying "i dont care if there are vars missing" and xampp says "nope" – Kevin Becker Nov 25 '18 at 00:25
  • Whoops looks like im wrong. if ill remove that three things, i still get the errors What could it be that it works with SELECT * FROM but not with all the information? – Kevin Becker Nov 25 '18 at 00:26
  • @KevinBecker Please update your question. I don't know what you are referring to but it sounds like the question is missing information now. – user3783243 Nov 25 '18 at 00:33
  • You have no data to fetch, so check your sql request. – TARiK Nov 25 '18 at 00:35
  • @KevinBecker How did this answer resolve your issue? (Per edit 3 it sounds like this answer did nothing to help you) – user3783243 Nov 25 '18 at 00:48