My goal is to put some numeric text in a text box, for example, if I entered “3”, it will come out:
Hello 1
Hello 2
Hello 3
My problem is that it keeps going until the loop entirely finishes (well 74 times), and not adhere to the entered value, and stop at 3 or some digit that I enter.
<div class="Container">
<h2>Hello Page</h2><hr>
<form>
<p>Enter a number:</p>
<input type="text" name="number">
<input type="submit" value="Enter">
</form>
<?php
$digit = $_GET['number'];
if (empty($digit))
$digit= "";
elseif (!empty($digit)) {
for ($digit= 1; $digit< 75; $digit++) {
if ($digit== TRUE) {
echo 'Hello ' . $digit. '<br>';
} elseif ($digit== $digit) {
break;
}
}
}
?>
</div>
Your $digit variable is the maximum, use it that way.
Change your for loop in this
Then you will get what you want.