PHP IF-Statement doesnt work like i want -
this question has answer here:
- in php, 0 treated empty? 14 answers
i started writing website learning html/css/js/php.
i designed front-end of site bootstrap. trying validate inputs php.
i tried this:
if ($durationhh <= 0 && $durationmm <= 0) { echo "durationhh , durationmm can not both 0 @ same time."; echo "<br>"; echo "durationhh , durationmm can not smaller 0."; } elseif (empty($durationhh) || empty($durationmm)) { echo "durationhh , durationmm can not empty."; echo "<br>"; } else { echo $_post["durationmm"]; echo ":"; echo $_post["durationhh"]; }
i tested validation putting in values durationhh , durationmm.
everything working fine far, except these 2 cases:
durationmm = 0 , durationhh = value
&&
durationhh= 0 , durationmm = value.
in these 2 cases output: "durationhh , durationmm can not empty."
how/why happen?
if durationhh , durationmm required integers or numeric, use ! is_numeric()
check.
Comments
Post a Comment