Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
PHP Help
I've been learning PHP for a while now and am just going over everything just so I know all the functions and how to use them for sure. I have already encountered a problem in one of my scripts. I was just making a simple counter and wanted to put bounds on the number your allowed to put in (In the script its supposed to only allow everything from 1-999). The only problem I have is when I try to print out the error for putting in a zero (I just remembered I shouldn't allow negatives >_<) it doesn't show anything. Can someone show me what I'm doing wrong so I can get this down perfectly? I can't seem to spot the error.
// user generated counter script
$count=1;
$random=$_GET["count_num"];
for ($num=$_GET["count_num"]; $count<=$num; $count++) {
if ($random==0) {
echo "Please input an allowed number. Your input: ".$_GET["count_num"]." was not acceptable.";
break;
}
elseif ($num>=1000) {
echo "Please input an allowed number. Your input: ".$_GET["count_num"]." was not acceptable.";
break;
}
echo $count;
echo "<br />";
}
?>
I know it's kinda bad coding, I've only been learning PHP for like 2 weeks now or so. I put in the $count=1; because without that it would have a blank spot when I put in any number and then it would continue on counting. So please help me out! Thanks, Kirk.
the problem is with this line:
markupfor ($num=$_GET["count_num"]; $count<=$num; $count++) {
if the input is 0, it won't execute the block following this line at all. if $count is 1 and $count is supposed to be <= $num, and if $num is 0 the check will return false, thus the loop won't execute.
I'd do the check before you do the loop, something like this:
if ($num == 0 || $num >= 1000)
echo "Invalid input, your input was " . $num;
//loop here