Coly010 Posted January 17, 2015 Share Posted January 17, 2015 I just installed my first ever copy of Mccodes V2. Everytime I use the staff panel to edit items, add items, crimes etc I keep getting an error saying one of the inputs is in a bad format, or that one of the fields have been left out. I've noticed it occurs when I have a 0 in a certain place. I went to the code and I can't see why there's an error. I'm assuming its something to do with $_POST[formdata] = (isset($_POST[formdata]) && is_numeric($_POST[formdata])) ? abs(intval($_POST[formdata])) : ' '; where formdata is whichever type of data that's sent. I can't see a problem with if(empty($_POST[formdata])){ } if the data is 0. any ideas? Quote Link to comment Share on other sites More sharing options...
Jax Posted January 18, 2015 Share Posted January 18, 2015 empty() is the problem as that returns true if the input is "0" (zero). See http://php.net/manual/en/function.empty.php in particular the return values section. Your tests are: $value = isset($_POST['key']) && is_numeric($_POST['key']) ? abs(intval($_POST['key'])) : ' '; I'd probably replace with $value = array_key_exists('key', $_POST) && ctype_digit($_POST['key']) ? $_POST['key'] : ' '; for positive integers, $value = array_key_exists('key', $_POST) && is_string($_POST['key']) ? $_POST['key'] : ' '; for strings and $value = array_key_exists('key', $_POST) && is_numeric($_POST['key']) ? $_POST['key'] : ' '; for numbers (negative integers, or decimal values). This is slightly stricter and performs better type checking as well as using the in this instance more correct array_key_exists rather the issset. Be careful the the default values as a single whitespace character is probably not what you want here. is_empty often catches out people, there are very few places I've found it to be the correct test to use. See http://php.net/manual/en/function.empty.php in particular. Quote Link to comment Share on other sites More sharing options...
Coly010 Posted January 18, 2015 Author Share Posted January 18, 2015 Thanks a lot! I wasn't aware that empty() returned true for zero, Ill go right out and say that's a flaw in the mc codes engine then. I'll go through the files and sort it out. Thanks [MENTION=70654]Jax[/MENTION] 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.