php newbie here. How do I retain the value of an array when I click the submit button? So this how the program works. The user will input a name and a seat number(between 1-25) and when the the user clicks submit button, the name will be added on the array and will be displayed on the table. It works for the first input but when i entered another name and seat number, the first input is deleted. Please help.
//this is where the user will input...
Student Name: <input type="text" name="name" id="name"><br>
Seat Number: <input type="text" name="seat" id="seat"><br>
<input type="submit" name="assign" value="Assign"> <?php echo $warning; ?>
//and this is my php code.
<?php
$students = array_fill(0, 25, NULL);//this is to make an empty array with the size of 25.
if(isset($_POST['assign'])){
$student = $_POST['name'];
$seat = $_POST['seat'];
if($seat > 25 || $seat < 1){
$warning = 'Seat number does not exist.';
}
else{
$warning = '';
$students[$seat-1] = $student;
}
}
?>
//This code here is just a part of the HTML code for the table. this is where the name will display.
<td id="box"><?php echo $students[0]; ?></td>
<td id="box"><?php echo $students[1]; ?></td>
<td id="box"><?php echo $students[2]; ?></td>
<td id="box"><?php echo $students[3]; ?></td>
<td id="box"><?php echo $students[4]; ?></td>