dongyi1996 2018-11-24 23:57
浏览 506

PHP注意:未定义的偏移量: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

  • 写回答

1条回答 默认 最新

  • dongren1977 2018-11-25 00:03
    关注

    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);

    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘