Jump to content
MakeWebGames

Staff Panel problems


Coly010

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...