= 3 && $number <= 1300)==FALSE) { $displayForm = TRUE; if (empty($errorMessage)) $errorMessage .= "Please enter a number between 3 and 1300."; else { $errorMessage .= " between 3 and 1300."; $errorMessage = str_replace("value.","value", $errorMessage); } } if (empty($errorMessage)) { $displayForm = FALSE; $prime = true; $div = 2; do { if ($number % $div == 0) $prime = false; else $div++; } while ($div < $number && $prime == true); return $prime; } } // some page level variables //$number = ""; //$prime = ""; //$errorMessage = ""; // tells me if the user has pressed the submit button // previous examples checked to see if isset($_POST['submit']) if (count ($_POST) > 0) { // get the number from the post array $number = $_POST['number']; // if the number is prime if (isPrime($number)) { $prime = "Yes"; } else { if (!empty($errorMessage)) { $prime = ""; } else { $prime = "No"; } } } if ($displayForm) { ?>
  • Enter the number here:
  • Answer: