未定义的索引变量 PHP


Undefined index variable PHP

好吧,这似乎很常见,但是我读到的东西都没有帮助我,所以有没有人知道为什么我的变量似乎没有设置。

编辑:抱歉忘记了错误的地方,它在169行,即:

if($world['$queryi'] != 0)
<?php
  if(isset($_GET['upgrade']))
  {
  if($_GET['upgrade'] > 0 && $_GET['upgrade'] < 15){ 
  $_GET['upgrade'];
  $id = $_GET['upgrade'];
  $queryi = "column_$id"; // This shows as undefined.
  $querye = "column_name_$id"; // This shows as undefined
  //When printing them out alone, they are defined, with the value i need them to be.
  if($id>=1 && $id <=14)
  {
//$world[] <- array from outside of the $_GET area (ive tried having it inside, same error)
   if($world['$queryi'] != 0)
   {
   }
   else
   {
       echo "query turned out zero";
   }
  }
  else
  {
      echo "something went wrong.";
  }
 }
 }
?>
//EDIT this is the arrayQUery which seems to be causing the problem..
$query = "SELECT * from this WHERE userid='".$user['id']."'";
$result = mysql_query($query);
$world=mysql_fetch_array($result);

有没有线索,怎么了?

更改

$_GET['upgrade'];
$id = $_GET['upgrade'];
$queryi = "column_$id"; // This shows as undefined.
$querye = "column_name_$id"; // This shows as undefined

if(isset($_GET['upgrade'])) { 
    $id = $_GET['upgrade'];
} else {
    $id = 1;
}
$queryi = "column_" . $id; // This shows as undefined.
$querye = "column_name_" . $id; // This shows as undefined

应该做这个伎俩。

此外,还需要检查此行是否已设置。我认为这会导致错误..:

if($world['$queryi'] != 0)

将其更改为:

if(isset($world[$queryi]) && $world[$queryi] != 0)

根据您的评论,我发现您的代码存在以下问题

你为什么在这行用单引号写$queryi if($world['$queryi'] != 0).因为单引号表示字符串不真实。所以你的代码的意思是,搜索索引"$queryi"。但是你要做的是,你想搜索这个字符串索引=> "column_name_$id"。因此,请删除单引号或将其更改为双引号。

所以正确的代码将是

if($world[$queryi] != 0)