I'm having a few problems with validating data. In the form I call about 50 variable names from the database, loop through them in a form providing an input box for the user to fill in the number of products needed.
I want to check that they've only inputted a number. Here's the code that doesn't work.
foreach($_POST as $variablename => $quantity)
{
if ( (!empty($quantity)) && (!is_int($quantity)) )
{
$nofilt = 'no';
$error = 'TRUE';
}
}
if ($nofilt == 'no')
{
echo 'Please only enter numbers.';
}
I follow this with
if (isset($error))
{
echo '<input type=button value=back onClick=history.back()>';
and finish up. If there isn't an error then I go onto the database queries and send an email.
Now something tells me that I've got this very wrong. I assume that it's looking at all 50 variables, working out that some are empty and some aren't and then returning TRUE for the $error. Hence the problem. What I can't figure out is how to make it check that only the variable names whose quantities were completed on the previous page are integers and if so returning $error as FALSE and continuing. Any help much appreciated.