Jump to content

[SOLVED] "Notice:" Errors, I have never ran into them before.


Tmal

Recommended Posts

Here are the Errors:

 

Notice: Undefined index: AEP in /home/gflores/public_html/includes/planetlist.php on line 25

Notice: Undefined index: name in /home/gflores/public_html/includes/planetlist.php on line 26

Notice: Undefined index: magi_ava in /home/gflores/public_html/includes/planetlist.php on line 27

Notice: Undefined index: sorci_ava in /home/gflores/public_html/includes/planetlist.php on line 28

Notice: Undefined index: time in /home/gflores/public_html/includes/planetlist.php on line 29

Notice: Undefined index: clan in /home/gflores/public_html/includes/planetlist.php on line 30

Notice: Undefined index: id in /home/gflores/public_html/includes/planetlist.php on line 31

Notice: Undefined variable: protectionIs in /home/gflores/public_html/includes/planetlist.php on line 79

Notice: Undefined index: in /home/gflores/public_html/includes/planetlist.php on line 82

 

Here is the code I made:

 

<?php
error_reporting (E_ALL);
/******************************************
*  Planets Listing - accountOverviewPage; *
*  Created By: Brian T. Flores            *
*  Creation Date: 7-22-2009               *
******************************************/

// Create the PlanetsListing Function

function getPlanetsListing($id){
// Select All of the Planet Information Where the Owner ID is Equal to the ID of the Current User.

$query1="select * from PlanetInfo WHERE `owner` = '$id' ORDER BY `id` ASC";  

// Get Resulting Information using a simple mysql_query.
$result = mysql_query($query1) or die(mysql_error());  // If a Error Display It


while($thisrow=mysql_fetch_row($result)){
  for ($i = 0; $i < mysql_num_rows($result);$i++)// For Loop.
  {
   // Below we will process needed infomation to variables in which we can call at a later time.
      
  $protection = $thisrow['AEP'];
  $planetname = $thisrow['name'];
  $resource_1 = $thisrow['magi_ava'];
  $resource_2 = $thisrow['sorci_ava'];
  $protectime = $thisrow['time'];
      $racetype   = $thisrow['clan'];
      $planetid   = $thisrow['id'];
      
$raceinform = array(1 =>"Human", 2 =>"Minor", 3 =>"Cretor", 4 =>"Clorian", 5 =>"Calarian", 6 =>"Taikan", 7 =>"Tiloan", 8 =>"Placorian");

     $sql = "SELECT * FROM `Army` WHERE `id` = '$planetid'";
     
         $result = mysql_query($sql) or die(mysql_error());  // If a Error Display It
  
 $armyrow =  mysql_fetch_row($result);

     $poplatent_planet   = $armyrow['latent'];
     $popawakened_planet = $armyrow['awakened'];
     $popcombat1_planet  = $armyrow['combat1'];
     $popcombat2_planet  = $armyrow['combat2'];
     $popcombat3_planet  = $armyrow['combat3'];
     $popcombat4_planet  = $armyrow['combat4'];
     $popmagi_planet     = $armyrow['magi'];
     $popadvm_planet     = $armyrow['advm'];
     $popcovert_planet   = $armyrow['covert'];
     $popgenstart_planet = $armyrow['lgstart'];
     $popgenoff_planet   = $armyrow['lgoff'];
     $popgendef_planet   = $armyrow['lgdef'];
     $popgencov_planet   = $armyrow['lgcov'];
     $popfarmer_planet   = $armyrow['farmer'];
   
   $poptotal_planet = $popawakened_planet + $popcombat1_planet + $popcombat2_planet + $popcombat3_planet + $popcombat4_planet + $popmagi_planet + $popcovert_planet + $popfarmer_planet + $popgenstart_planet + $popgenoff_planet + $popgendef_planet + $popgencov_planet;

     $sql = "SELECT * FROM `AllRanks` WHERE `id` = '$planetid'";
   
        $result = mysql_query($sql) or die(mysql_error());  // If a Error Display It
  
 $ranks =  mysql_fetch_row($result);

    $planetrank = $ranks['Rank'];

    if($protection==1) // Lets see if the Planet is Under Protection
{
  
   $protectionIs="font color='yellow'>Under Protection</font>"; // If it is we will add a protection marker.
  
}

  //Else - Do Nothing.
  
   


    $colony = "<tr>
<td align='left' width='30%'><a href='enterPlanet.php?id=".$planetid.">".$planetname."</a> ".$protectionIs."</td>
<td align='left' width='12%'>".$planetrank."</td>
<td align='left' width='12%'>".$poptotal_planet."</td>
<td align='left' width='12%'>".$raceinform[$racetype]."</td>
<td align='right' width='10%'>".$resource_1."</td>
<td align='right' width='10%'>".$resource_2."</td>

</tr>";

die($colony);
    echo $colony;  // Echo Out the $colony Var.
  }
}
}

?>

Link to comment
Share on other sites

This error appears because of your PHP error reporting settings. Usually, it appears when your variable is not properly set. There are two ways to handle this issue:

 

1. Check if $_POST['action'] is set before using it. For example:

 

if (!isset($_POST['action']))

{

//If not isset -> set with dumy value

$_POST['action'] = "undefine";

}

 

2. Suppress Notice warnings

 

Notice warnings could be suppressed by changing the error_reporting variable in your PHP.ini. error_reporting could be set to show all errors except those for notices and coding standards warnings: error_reporting = E_ALL & ~E_NOTICE

 

The same is accomplished by adding the following line in your php page:

 

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

Link to comment
Share on other sites

mysql_fetch_row() does not return an associative array. Therefore, the index names being referenced in the code don't exist.

 

Use mysql_fetch_assoc()

 

@ldougherty, don't suggest hiding error messages. That just hides the root cause of the problem.

Link to comment
Share on other sites

I would not recommend suppressing errors, even notices.  A notice will not halt the execution of a script, but they could nonetheless cause you trouble.  For instance, are you expecting results from that query whenever it is run?  If you are, then your script will happily keep running its course, without those expected variables.  This could cause any number of errors down the road. 

 

You should script your code not to have any errors in the first place, even notices.  One way to do that would be to use a condition with a count on mysql_num_rows before running the while loop.  If it is > 0, run the loop.  else, do something else (or nothing, depending on what this script is supposed to be doing).

 

@PFM ah good eye, I missed that fetch_row

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.