Lewis Seddon Lewis Seddon - 2 months ago 5
HTML Question

POST with forms is not showing results

The PHP of my code works as I have tested it within a PHP checker online but when trying to run the page online, after clicking the button to submit the number the page does not display anything. Any idea?

<?php
if(isset($_POST['btn-submit_number']))
{
$number = ($_POST['number']);
for($i=1;$i<($number+1); $i++){
if (($i % 3 == 0) && ($i % 7 == 0)){
echo "Hello World";
}
else if (($i % 3 == 0) && ($i % 7 != 0)){
echo "Hello";
}
else if (($i % 7 == 0) && ($i % 3 != 0)){
echo "World";
}
else{
echo $i;
}
print "\n";
}
}
?>

<form method="post">
<br>
<label for="number">Enter your number here:</label>
<input type="text" id="number" name="number" required>

<button type="submit" name="btn-submit_number">Submit</button>
</form>

</body>
</html>

Answer

"after clicking submit" - Did you enter a number in there at all, or a string? Again, I can't see this failing. Is PHP available on the server you're wanting to use? I've seen some (free) servers that don't let you use PHP. If you're using this on your own machine, how are you accessing this as; http://localhost or as file:///? Question's unclear. what browser are you using? – Fred -ii-

@Fred-ii- apologies for the unclear question, I am accessing it via file:/// should I be using localhost? – Lewis Seddon 19 secs ago

There you go. Yes, you need to use http://localhost and not file:///.

PHP isn't being parsed and make sure you have a webserver and PHP installed.

Comments