completeamateur Posted June 20, 2008 Share Posted June 20, 2008 I just turned on all error reporting in php and its spuing out loads of errors all over my local site. The most common being trying to GET or POST a non-existant variable. What should I do? Ignore it or add something like this: if(isset($_POST["username"])) { $username = $_POST["username"]); } Regards. Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 20, 2008 Share Posted June 20, 2008 Thats because it reports warnings when you use fields that you havent declared, it works fine but it gives warnings You can remove the warnings using: error_reporting(E_ERROR | E_WARNING | E_PARSE); or by editing the ini file again. Or you could put the isset checks in, thats the proper way that php should be coded Quote Link to comment Share on other sites More sharing options...
completeamateur Posted June 20, 2008 Author Share Posted June 20, 2008 blimey, surely that adds a lot of unnecessary weight to files. Quote Link to comment Share on other sites More sharing options...
phpzone Posted June 20, 2008 Share Posted June 20, 2008 Write a wrapper function and use the wrapper, something like: <?php function GetVariable( $name ) { if ( isset( $_GET[ $name ] ) ) { return $_GET[ $name ]; } else { // whatever to do if it doesn't exist } } $name = GetVariable("username"); ?> Obviously code in your $_POST/$_SERVER stuff etc. where required. Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted June 20, 2008 Share Posted June 20, 2008 completeamateur, While developing, it is good to see those messages... suppose you were expecting to see $_GET[school_name]; back from a form, but you get: Informational message: '$_GET[skool_name] is uninitialized ' ... Pretty good clue that you have something misspelled somewhere... Scot Diddle, Richmond VA 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.