Miks Posted April 6, 2015 Share Posted April 6, 2015 (edited) Happy Easter everyone, well those that know the meaning, otherwise happy chocolate egg holiday! Anyway, moving on to business..... As my knowledge "slowly" grows I learn and come across new things, I have a play, hit a brick wall and then seek help! So at the moment I am sticking error_reporting into all my work, I bet you can imagine the fun I am having now, the saying ignorance is bliss comes to mind! I have only turned error reporting on to one mod, the city park. I am getting this notice, even though its a notice I would like to resolve it Notice: Undefined index: spend in /home/public_html/citypark.php on line 27 <?php include "globals.php"; error_reporting(E_ALL); if($ir['jail']) { print "<div class='desc2'> <div class='citstat'> <table class='mytable'><tr><td><center><BR> You cant go any further while you're in jail <BR><a href='jail.php'>Go back to jail</a> <BR><BR></center></td></tr></table>"; $h->endpage(); exit; } if($ir['hospital']) { print "<div class='desc2'> <div class='citstat'> <table class='mytable'><tr><td><center><BR> You can go any further while your in hospital <BR><a href='hospital.php'>Go back to Hospital</a> <BR><BR></center></td></tr></table>"; $h->endpage(); exit; } if(!$_GET['spend']) { print " <div class='desc2'> <div class='citstat'> <style type='text/css'> } </style> <h2>Welcome to the City Park!</h2> <br /> You walk up to a weird looking fountain, you see an old glass with lots of scratches and brown patches.<BR><BR> Do you take a drink?<BR> <br /> <table class=mytable> <th>Fountain</th> <tr><td><a href='citypark.php?spend=yes'><center>Yes</center></a></td></tr> <tr><td><a href='citypark.php?spend=no'><center>No!</center></a></td></tr> </table> </div> "; } else { if($_GET['spend'] == 'yes') { if($ir['citypark'] == 1) { print "<div class='desc2'> <div class='citstat'>This has no effect on you"; } else { $db->query("UPDATE `users` SET `energy`=maxenergy,`citypark`=1 WHERE `userid`=$userid"); print "<div class='desc2'> <div class='citstat'>You have an almighty gulp and magically it restores your energy, awesome!"; } } if($_GET['spend'] == 'no') { print " <div class='desc2'> <div class='citstat'> Wise choice buddy wise choice!"; } } $h->endpage(); ?> I'm hoping someone could explain what this means exactly and how to go about resolving it....maybe an example using my code to make it easier to understand? I'm guessing I havent defined if(!$_GET['spend']) but how would I do that? Also why does this particular GET have a "!" at the beginning? If I remove "!" the feature stops working and displays all 3 warnings about undefined GET thingys (I have 3 undefined GETs in totol) Edited April 6, 2015 by Miks Quote Link to comment Share on other sites More sharing options...
G7470 Posted April 6, 2015 Share Posted April 6, 2015 Well, you were right that it has to do with this line: if(!$_GET['spend']) In relation to this error: "Notice: Undefined index: spend in /home/public_html/citypark.php on line 27" This is because you are attempting to check the value of $_GET['spend'] without evaluating whether the variable is even set or not. (I have seen this MANY times and it is very poor programming practice to keep this as-is.) So, to fix this problem, you will want to check whether or not $_GET['spend'] is set: if(isset($_GET['spend']) && !$_GET['spend']) { print " <div class='desc2'> <div class='citstat'> <style type='text/css'> } isset() in PHP manual: http://php.net/manual/en/function.isset.php That should remove the notice. This notice is actually pretty informative as to what the problem is, so if you encounter a notice like this again, watch for these evaluation statements (if, switch, while, for) checking variables. Make sure that variable is explicitly set first before evaluating its value. If not, then you should first evaluate whether it is set or not BEFORE evaluating its value. :) Hope this helps! ~G7470 Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted April 6, 2015 Share Posted April 6, 2015 You think that is bad try turn error report on using grpg now there is a fun job :P Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted April 6, 2015 Share Posted April 6, 2015 You think that is bad try turn error report on using grpg now there is a fun job :P Been there, done that, manually repaired every single error - took me about 4 days of NonStopCoding! ;) Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted April 6, 2015 Share Posted April 6, 2015 haha liked :D Quote Link to comment Share on other sites More sharing options...
G7470 Posted April 7, 2015 Share Posted April 7, 2015 Been there, done that, manually repaired every single error - took me about 4 days of NonStopCoding! ;) You weren't the only one who repaired all of those errors...took such a long time. Lol. ~G7470 Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted April 7, 2015 Share Posted April 7, 2015 iv yet to begin mine (starts crying) EDIT: oops forgot i fixed a few but only a few Quote Link to comment 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.