Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

number in $_POST returns invalid number when validated as a number

Avatar of czechmate1976
czechmate1976Flag for United Kingdom of Great Britain and Northern Ireland asked on
PHP
16 Comments1 Solution406 ViewsLast Modified:
I am trying to validate a number and my function always return invalid number. I am using a function with a FILTER_VALIDATE_INT, which I posted now below. I can't figure why it would not validate a number from the $_POST inserted via a form. Please help or I will waste so much time I don't have :-/ Thanks to everyone

I tried to test the value as follows:
echo is_int($_POST['category']) ? "true<br />" : "false<br />"; and it also returns FALSE. What am I doing wrong?
private function validateNumeric($var, $min=0, $max=0, $required=false)
    {
        if($required==false && strlen($this->source[$var]) == 0)
        {
            return true;
        }
        if(filter_var($this->source[$var], FILTER_VALIDATE_INT, array("options" => array("min_range"=>$min, "max_range"=>$max)))===FALSE)
        {
            $this->errors[$var] = $var . ' is an invalid number';
        } 
    }
ASKER CERTIFIED SOLUTION
Avatar of zac_charles
zac_charlesFlag of Australia image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answers