doujing6436 2014-06-01 18:22
浏览 21

Php等于或多或少运算符[关闭]

I am getting the following Error:

$experience = $row[Experience]; Use of undefined constant Experience - assumed 'Experience' – user3696343 )

From this code:

} else if($_GET['event'] == 15) {
      $fetch = mysqli_query($db_handle, "SELECT Gold, Bank, Troop, Head, Body, Gloves, Foot, CombatLog, Item0, Item1, Item2, Item3, CoordinateX, CoordinateY, CoordinateZ, Horse, Hp, New, Food, Experience, Level FROM playerdata WHERE Unique_Id = '$unique_id'");
      $row = mysqli_fetch_assoc($fetch);
     $experience = $row[Experience];
      $xptolevel = '50';
      if($experience >= $xptolevel) {
      echo'Enough Xp to level up'; 
      mysqli_query($db_handle, "UPDATE playerdata SET Experience = 0, Level = Level + 1 WHERE Unique_ID = '$unique_id'");     
      echo "15|$unique_id|$local_id|$row[Gold]|$row[Bank]|$row[Troop]|$row[Head]|$row[Body]|$row[Gloves]|$row[Foot]|$row[CombatLog]|$row[Item0]|$row[Item1]|$row[Item2]|$row[Item3]|$row[CoordinateX]|$row[CoordinateY]|$row[CoordinateZ]|$row[Horse]|$row[Hp]|$row[New]|$row[Food]|$row[Level]|$row[Experience]|";
      } else {
      echo'Not enough XP to level up';
  }
  }

I hope someone can help

  • 写回答

1条回答 默认 最新

  • dongna1593 2014-06-01 18:25
    关注

    When you access an associative array element, add the quotes:

    $row[Experience] becomes $row['Experience']
    

    If you use Experience, it assumes you are trying to use the constant Experience which doesn't exist but PHP converts to string for you. It works, but with a notice.

    If you need to use it within a quotes, you use the {} around it:

    echo "Some String {$row['Experience']}";
    

    Finally, your SQL code is not safe. Always use parametrized queries instead of injecting the actual variables in your SQL.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line