Ads Posted January 11, 2011 Share Posted January 11, 2011 Hey I updated my WAMP server the other day and I am getting al of these Errors now. Notice: Undefined variable: ac in C:\wamp\www\xxxxx\newupdates.php on line 15 And there is about 25 of them on one page, and they are all over the place. Undoubtly it is my poor coding, but how come it never showed up before, and the site itself still works. Any help would be great, I basically wont to get rid of these Quote Link to comment Share on other sites More sharing options...
noXstyle Posted January 11, 2011 Share Posted January 11, 2011 The best guess would be that the update enabled php warnings which you didn't have on before... You can always turn the warnings off if you find them irritating (not suggested tho on dev machines). Without any proper knowledge about your code my best guess would be to wrap those variables inside if(isset) blocks. e.g. if(isset($yourvar)) { //dosomething with your var } Quote Link to comment Share on other sites More sharing options...
phil88 Posted January 12, 2011 Share Posted January 12, 2011 Different servers are set up to show different levels of errors. PHP Notices are often not shown. That particular notice occurs if you try and use a variable before it has been set. for($i = 0; $i < 5; $i++){ $var = $var + 1; } will cause PHP to issue a notice because the first time around the loop, you're trying to add 1 to $var before $var exists. To avoid this notice, you could do something like; Different servers are set up to show different levels of errors. PHP Notices are often not shown. That particular notice occurs if you try and use a variable before it has been set. $var = 0; for($i = 0; $i < 5; $i++){ $var = $var + 1; } Or, to use noXstyle's example code; for($i = 0; $i < 5; $i++){ if(isset($var)){ $var = $var + 1; }else{ $var = 1; } } Quote Link to comment Share on other sites More sharing options...
Ads Posted January 12, 2011 Author Share Posted January 12, 2011 For this particle example I have a lot of variables, as it is a flag system for the members. Do i have to code each Variable in, or is there an easier way to do it. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 12, 2011 Share Posted January 12, 2011 It's telling you that your variables are not defined when it first runs. What you want to do with that is up to you. Quote Link to comment Share on other sites More sharing options...
Ads Posted January 12, 2011 Author Share Posted January 12, 2011 It's telling you that your variables are not defined when it first runs. What you want to do with that is up to you. I just want to get rid of it The most easy and painless way possible Quote Link to comment Share on other sites More sharing options...
phil88 Posted January 12, 2011 Share Posted January 12, 2011 The easiest way is to just disable the display of PHP Notices by changing the error_reporting level. But just hiding the messages doesn't fix your code You could just initialise the problematic variables at the start of the code segment. Eg; $a = $b = $c = $d = $e = 0; What you initialise them to will depend on your code. 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.