Tmal Posted July 22, 2009 Share Posted July 22, 2009 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. } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167049-solved-notice-errors-i-have-never-ran-into-them-before/ Share on other sites More sharing options...
.josh Posted July 22, 2009 Share Posted July 22, 2009 It looks like your query is either failing or else returning 0 results (I assume the latter, or else you would be seeing a mysql_error from your die() ), and therefore $thisrow['AEP'] etc... do not exist. It is just a notice; php telling the element for that array does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/167049-solved-notice-errors-i-have-never-ran-into-them-before/#findComment-880818 Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/167049-solved-notice-errors-i-have-never-ran-into-them-before/#findComment-880820 Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2009 Share Posted July 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167049-solved-notice-errors-i-have-never-ran-into-them-before/#findComment-880824 Share on other sites More sharing options...
.josh Posted July 22, 2009 Share Posted July 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167049-solved-notice-errors-i-have-never-ran-into-them-before/#findComment-880829 Share on other sites More sharing options...
Tmal Posted July 22, 2009 Author Share Posted July 22, 2009 Thank you PFMaBiSmAd, mysql_fetch_assoc(); worked! All Errors gone and it is working smoothly thank you alot. Brian Flores Quote Link to comment https://forums.phpfreaks.com/topic/167049-solved-notice-errors-i-have-never-ran-into-them-before/#findComment-880831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.