I am working on a php script whereby I have to a form with 2 input fields, consisting of a name and id. When I input a name and a id, these are stored in an associative array. As long as an id is less or equal to 100, the names and ids are stored in an associative array. When an id greater than 100 is entered, the php script will display the names entered previously and their corresponding ids are displayed. However, when I enter the names and Ids, only one name and one Id is being displayed, and the current ones being replaced. I want a list of names and Ids to be displayed when I enter an Id greater than 100 irrespective of the name entered. See my codes below:
<?php
$id = 100;
if(isset($_POST['lname']) && isset($_POST['id'])) {
$name = $_POST['lname'];
$ids = $_POST['id'];
while($GLOBALS['id'] <= 100) {
$lists = array($name => $ids);
foreach($lists as $key => $val) {
echo $key . ' ' . $val . '<br>';
}
}
}
?>
<form action = "index.php" method = "POST">
Name:<br>
<input type = "text" name = "lname"><br><br>
Marks:<br>
<input type = "text" name = "id"><br><br>
<input type = "submit" value = "Submit">
</form>