Code: Select all
(filter_var($gamescore['AwayScore'], FILTER_VALIDATE_INT, array('Options'=>array('min_range'=>0))))I can put in positive or negative numbers, but not zero. I want it to basically be allowed to be >= 0.
Any recommendations?
Moderator: General Moderators
Code: Select all
(filter_var($gamescore['AwayScore'], FILTER_VALIDATE_INT, array('Options'=>array('min_range'=>0))))Code: Select all
var_dump($gamescore['AwayScore']);Code: Select all
if (false !== filter_var($score, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0)))) {
// ok
} else {
// validation failed
}
Code: Select all
foreach($_POST as $array)
{#A
foreach($array as $gamescore)
{#B
#Check to see that something was input
IF($gamescore['AwayScore']!='' && $gamescore['HomeScore']!='')
{#C
#Check to see that scores were positive integers
IF((filter_var($gamescore['AwayScore'], FILTER_VALIDATE_INT, array('Options'=>array('min_range'=>0)))) AND
(filter_var($gamescore['HomeScore'], FILTER_VALIDATE_INT, array('Options'=>array('min_range'=>0)))))
{#D
$scoreupdate = "UPDATE Schedule SET AwayScore = '$gamescore[AwayScore]',
HomeScore = '$gamescore[HomeScore]' WHERE GameID = '$gamescore[GameID]'";
#Update the records
IF(!$update = mysqli_query($cxn, $scoreupdate))
{#E
echo "Couldn't update record.<br />"
."Please contact the WebMaster.";
}#E
#Echo update success
ELSE
{#F
echo "Game #".$gamescore[GameID]. " has been updated.<br />";
}#F
}#D
ELSE
{#G
echo "Please ensure scores are whole numbers only.<br />";
}#G
}#C
}#B
}#A
Code: Select all
IF(preg_match("/^[0-9]{1,2}$/", $gamescore['AwayScore'])) AND (preg_match("/^[0-9]{1,2}$/", $gamescore['HomeScore']))