未定义的索引和更新查询

时间:2017-11-11 12:34:22

标签: php mysql

我正在从数据库加载一个变量以显示在配置文件中,但是当我尝试加载它时,总是只对两个变量说undefined index。所有其他变量都有效,只有这两个变量不起作用。

  

注意:未定义的索引:第347行的F:\ xamp \ htdocs \ Adminx \ function \ updateinfo.php中的电子邮件

     

注意:未定义的索引:第349行的F:\ xamp \ htdocs \ Adminx \ function \ updateinfo.php中的警告

if ($num == 1) {
    $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    $pname = $row['Username'];
    $pkills = $row['Kills'];
    $pdeaths = $row['Deaths'];
    $pscore = $row['Level'];
    $pmoney = $row['Money'];
    $padmin = $row['Admin'];
    $pvip = $row['VIP'];
    $pbank = $row['BankMoney'];
    $probskill = $row['RobbersKilled'];
    $pterskill = $row['CopsKilled'];
    $pskin = $row['Skin'];
    $pipadr = $row['IP'];
    $pemail = $row['Email'];   ....line 347
    $pwarnings = $row['Warnings'];  .... line 349
}

这是我在管理层提交更新表单后发送更新查询的方式:

if (!empty($_POST['oldusername']) || !empty($_POST['Skin']) ||
    !empty($_POST['newusername']) || !empty($_POST['Password']) ||
    !empty($_POST['Kills']) || !empty($_POST['Deaths']) ||
    !empty($_POST['Level']) || !empty($_POST['Money']) ||
    !empty($_POST['BankMoney']) || !empty($_POST['Admin']) ||
    !empty($_POST['VIP']) || !empty($_POST['RobbersKilled']) ||
    !empty($_POST['CopsKilled']) || !empty($_POST['ipadr']) ||
    !empty($_POST['Email']) || !empty($_POST['Warnings'])) {
    $username = mysqli_real_escape_string($con, $_POST['oldusername']);
    $nusername = mysqli_real_escape_string($con, $_POST['newusername']);
    $skin = mysqli_real_escape_string($con, $_POST['Skin']);
    $password = strtoupper(hash('whirlpool', mysqli_real_escape_string($con, $_POST['Password'])));
    $kills = mysqli_real_escape_string($con, $_POST['Kills']);
    $deaths = mysqli_real_escape_string($con, $_POST['Deaths']);
    $score = mysqli_real_escape_string($con, $_POST['Level']);
    $money = mysqli_real_escape_string($con, $_POST['Money']);
    $bank = mysqli_real_escape_string($con, $_POST['BankMoney']);
    $admin = mysqli_real_escape_string($con, $_POST['Admin']);
    $vip = mysqli_real_escape_string($con, $_POST['VIP']);
    $robskill = mysqli_real_escape_string($con, $_POST['RobbersKilled']);
    $terskill = mysqli_real_escape_string($con, $_POST['CopsKilled']);
    $ipadr = mysqli_real_escape_string($con, $_POST['ipadr']);
    $email = mysqli_real_escape_string($con, $_POST['Email']);
    $warnings = mysqli_real_escape_string($con, $_POST['Warnings']);

    if ($skin == 265) $team = 2;
    else if ($skin == 266) $team = 2;
    else if ($skin == 267) $team = 2;
    else if ($skin == 280) $team = 2;
    else if ($skin == 281) $team = 2;
    else if ($skin == 282) $team = 2;
    else if ($skin == 283) $team = 2;
    else if ($skin == 284) $team = 2;
    else if ($skin == 288) $team = 2;
    else if ($skin == 286) $team = 3;
    else if ($skin == 285) $team = 4;
    else if ($skin == 287) $team = 5;
    else if ($skin == 274) $team = 1;
    else if ($skin == 275) $team = 1;
    else if ($skin == 276) $team = 1;
    else if ($skin == 163) $team = 6;
    else if ($skin == 164) $team = 6;
    else if ($skin == 165) $team = 6;
    else if ($skin == 166) $team = 6;
    else $team = 0;

    if ($_POST['Password'] == "Crypted")
        $query1 = "UPDATE `players` SET `Username`='$nusername',`Kills`='$kills',`Deaths`='$deaths',`Level`='$score',`Money`='$money',`Admin`='$admin',`VIP`='$vip',`Email`='$email',`BankMoney`='$bank',`RobbersKilled`='$robskill',`CopsKilled`='$terskill',`Warnings`='$warnings',`Skin`='$skin',`Team`='$team' WHERE `Username`='$username' LIMIT 1";
    else
        $query1 = "UPDATE `players` SET `Username`='$nusername',`Password`='$password',`Kills`='$kills',`Deaths`='$deaths',`Level`='$score',`Money`='$money',`Admin`='$admin',`VIP`='$vip',`Email`='$email',`BankMoney`='$bank',`RobbersKilled`='$robskill',`CopsKilled`='$terskill',`Warnings`='$warnings',`Skin`='$skin',`Team`='$team' WHERE `Username`='$username' LIMIT 1";
    mysqli_query($con, $query1);

这是查询的打印:

UPDATE `players`
    SET `Username`='vassilis',`Kills`='4',`Deaths`='9',`Level`='4',`Money`='94300',`Admin`='5',`VIP`='3',`Email`='sadsa@gmail.com',`BankMoney`='1133001',`RobbersKilled`='0',`CopsKilled`='0',`Warnings`='23',`Skin`='7',`Team`='0'
    WHERE `Username`='vassilis' LIMIT 1

查询没有被发送,我只是感到困惑。

这是我用来更新播放器的完整代码

 if(isset($_SESSION['loggedin']))
{
  if($_SESSION['adminlvl'] >2)
  {
    if(!empty($_GET['user']))
    {
      $user=$_GET['user'];
    }
  elseif(empty($_GET['user'])) 
  {
    if(!empty($_POST))
    {
        if(!empty($_POST['oldusername']) || !empty($_POST['Skin']) || !empty($_POST['newusername']) || !empty($_POST['Password']) || !empty($_POST['Kills']) || !empty($_POST['Deaths']) || !empty($_POST['Level']) || !empty($_POST['Money']) || !empty($_POST['BankMoney']) || !empty($_POST['Admin']) || !empty($_POST['VIP']) || !empty($_POST['RobbersKilled']) || !empty($_POST['CopsKilled']) || !empty($_POST['ipadr']) || !empty($_POST['Email']) || !empty($_POST['Warnings']))     
      {
          $username = mysqli_real_escape_string($con, $_POST['oldusername']);
          $nusername = mysqli_real_escape_string($con, $_POST['newusername']);
          $skin = mysqli_real_escape_string($con, $_POST['Skin']);
          $password = strtoupper(hash('whirlpool',mysqli_real_escape_string($con, $_POST['Password'])));
          $kills = mysqli_real_escape_string($con, $_POST['Kills']);
          $deaths = mysqli_real_escape_string($con, $_POST['Deaths']);
          $score = mysqli_real_escape_string($con, $_POST['Level']);
          $money = mysqli_real_escape_string($con, $_POST['Money']);
          $bank = mysqli_real_escape_string($con, $_POST['BankMoney']);
          $admin = mysqli_real_escape_string($con, $_POST['Admin']);
          $vip = mysqli_real_escape_string($con, $_POST['VIP']);
          $robskill = mysqli_real_escape_string($con, $_POST['RobbersKilled']);
          $terskill = mysqli_real_escape_string($con, $_POST['CopsKilled']);
          $ipadr = mysqli_real_escape_string($con, $_POST['ipadr']);
          $email = mysqli_real_escape_string($con, $_POST['Email']);
          $warnings = mysqli_real_escape_string($con, $_POST['Warnings']);

          if($skin == 265) $team = 2;
          else if($skin == 266) $team = 2;
          else if($skin == 267) $team = 2;
          else if($skin == 280) $team = 2;
          else if($skin == 281) $team = 2;
          else if($skin == 282) $team = 2;
          else if($skin == 283) $team = 2;
          else if($skin == 284) $team = 2;
          else if($skin == 288) $team = 2;
          else if($skin == 286) $team = 3;
          else if($skin == 285) $team = 4;
          else if($skin == 287) $team = 5;
          else if($skin == 274) $team = 1;
          else if($skin == 275) $team = 1;
          else if($skin == 276) $team = 1;
          else if($skin == 163) $team = 6;
          else if($skin == 164) $team = 6;
          else if($skin == 165) $team = 6;
          else if($skin == 166) $team = 6;
          else $team = 0;

          if ($_POST['Password'] == "Crypted") $query1 = "UPDATE `players` SET `Username`='$nusername',`Kills`='$kills',`Deaths`='$deaths',`Level`='$score',`Money`='$money',`Admin`='$admin',`VIP`='$vip',`Email`='$email',`BankMoney`='$bank',`RobbersKilled`='$robskill',`CopsKilled`='$terskill',`Warnings`='$warnings',`Skin`='$skin',`Team`='$team' WHERE `Username`='$username'";
          else $query1 = "UPDATE `players` SET `Username`='$nusername',`Password`='$password',`Kills`='$kills',`Deaths`='$deaths',`Level`='$score',`Money`='$money',`Admin`='$admin',`VIP`='$vip',`Email`='$email',`BankMoney`='$bank',`RobbersKilled`='$robskill',`CopsKilled`='$terskill',`Warnings`='$warnings',`Skin`='$skin',`Team`='$team' WHERE `Username`='$username'";
          mysqli_query($con, $query1);


          echo "<h2><b>Success</b></h2></br></br>
              <div class='alert alert-success' role='alert'>You have successfully updated <b><a href='profile.php?user=$username'>$username</a></b>'s player information.</div>
              <meta http-equiv='Refresh' content='4;url=updateplayer.php'/>";
      }
      else
      {
        echo "<h2><b>Error</b></h2></br></br>";
        echo "<div class='alert alert-danger' role='alert'>An error with the page occurred.</div>";
        echo "<meta http-equiv='Refresh' content='2;url=updateplayer.php'/>";
      }

    }
    else
    {
      echo "<div class='well'>";
      echo "<h2>Error</h2>";
      echo "<div class='alert alert-danger' role='alert'>No user entered.</div>";
      echo "</div>";
      echo "<meta http-equiv='Refresh' content='2;url=updateplayer.php' />";
      echo "</div>";
      mysqli_close($con);
    }
}
if (isset($user))
{
$query = "SELECT * FROM `players` WHERE `Username`='$user'";
$result=mysqli_query($con, $query);
$num=mysqli_num_rows($result);

    if($num == 1)
    {
      $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
      $pname = $row['Username'];
      $pemail = $row['Email'];
      $pkills = $row['Kills'];
      $pdeaths = $row['Deaths'];
      $pscore = $row['Level'];
      $pmoney = $row['Money'];
      $padmin = $row['Admin'];
      $pvip = $row['VIP'];
      $pwarnings = $row['Warns'];
      $pbank = $row['BankMoney'];
      $probskill = $row['RobbersKilled'];
      $pterskill = $row['CopsKilled'];
      $pskin = $row['Skin'];

      $pipadr = $row['IP'];



      echo "
      <div class='well'>
        <div class='row featurette'>
        <form class='form-signin' action='updateinfo.php' method='post'>
        <div class='col-md-5'>
          </br></br></br></br></br></br></br>
          <center><img class='featurette-image img-responsive' src='../skins/$pskin.png' width='100' height='200' alt='Skin'></center>
          </br></br><center><p>Skin ID: <input type='text' class='form-control' name='Skin' value='$pskin' /></p></center>
        </div>
        <div class='col-md-7'>
          <h2 class='featurette-heading'><a href='profile.php?user=$pname'><FONT COLOR='#303030'>$pname</FONT></a><input type='text' class='form-control' name='newusername' value='$pname' /></h2>
          <p class='lead'><strong>Stats</strong></p>
          <div class='col-md-9'>
          <table class='table'>
          <tbody>
            <tr>
            <td><strong>Password</strong></td>
            <td><center><input type='text' class='form-control' name='Password' value='Crypted' /></center></td>
            </tr>
            <tr>
            <td><strong>Kills</strong></td>
            <td><center><input type='text' class='form-control' name='Kills' value='$pkills' /></center></td>
            </tr>
            <tr>
            <td><strong>Deaths</strong></td>
            <td><center><input type='text' class='form-control' name='Deaths' value='$pdeaths' /></center></td>
            </tr>
            <tr>
            <td><strong>Level</strong></td>
            <td><center><input type='text' class='form-control' name='Level' value='$pscore' /></center></td>
            </tr>
            <tr>
            <td><strong>Money</strong></td>
            <td><center><input type='text' class='form-control' name='Money' value='$pmoney' /></center></td>
            </tr>
            <tr>
            <td><strong>Bank Money</strong></td>
            <td><center><input type='text' class='form-control' name='BankMoney' value='$pbank' /></center></td>
            </tr>
            <tr>
            <td><strong>Admin Level</strong></td>
            <td><center><input type='text' class='form-control' name='Admin' value='$padmin' /></center></td>
            </tr>
            <tr>
            <td><strong>Vip Level</strong></td>
            <td><center><input type='text' class='form-control' name='VIP' value='$pvip' /></center></td>
            </tr>
            <tr>
            <td><strong>Robbers killed</strong></td>
            <td><center><input type='text' class='form-control' name='RobbersKilled' value='$probskill' /></center></td>
            </tr>
            <tr>
            <td><strong>Cops killed</strong></td>
            <td><center><input type='text' class='form-control' name='CopsKilled' value='$pterskill' /></center></td>
            </tr>
          </tbody>
          </table></br>
          <p class='lead'><strong>Admin Info</strong></p></br>
          <table class='table'>
          <tbody>
            <tr>
            <td><strong>IP</strong></td>
            <td><center><input type='text' class='form-control' name='ipadr' value='$pipadr' /></center></td>
            </tr>
            <tr>
            <td><strong>E-Mail</strong></td>
            <td><center><input type='text' class='form-control' name='Email' value='$pemail' /></center></td>
            </tr>
            <tr>
            <td><strong>Warnings</strong></td>
            <td><center><input type='text' class='form-control' name='Warnings' value='$pwarnings' /></center></td>
            </tr>
          </tbody>
          </table>
          <input type='hidden' name='oldusername' value='$pname'>
          <input type='submit' class='btn btn-info' value='Submit' /> 
          </br>";
      echo "</div>
        </div>
        </form>
        </div>
      </div>
      ";
    }
    else
    {
      echo "<div class='well'>";
      echo "<h2>Error</h2>";
      echo "<div class='alert alert-danger' role='alert'>No user was found.</div>";
      echo "</div>";
      echo "<meta http-equiv='Refresh' content='2;url=updateplayer.php' />";
    }
    mysqli_free_result($result);
  }
}
else
{
echo "<h2><b>Error</b></h2></br></br>";
  echo "<div class='alert alert-danger' role='alert'>Your admin level is not high enough to access this page.</div>";
  echo "<meta http-equiv='Refresh' content='2;url=../core/login.php'/>";
}
}
?>

1 个答案:

答案 0 :(得分:-2)

您是否存在电子邮件和警告存在的问题。也许变量名称存在一些问题? Same error