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. Link to comment https://forums.phpfreaks.com/topic/111153-proper-coding/ 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 Link to comment https://forums.phpfreaks.com/topic/111153-proper-coding/#findComment-570458 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. Link to comment https://forums.phpfreaks.com/topic/111153-proper-coding/#findComment-570461 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. Link to comment https://forums.phpfreaks.com/topic/111153-proper-coding/#findComment-570462 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 Link to comment https://forums.phpfreaks.com/topic/111153-proper-coding/#findComment-570472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.