How To Submit A Single Form Value Multiple Times And Store (preserve) Them In An Array Each Time That I Refresh My Page?
Attempt 1: This shows what I want to achieve. The same array but different key and value pair.When printed, it list out all the keys and values.
Solution 1:
You can use session to achieve what you want, see this code:
<?php
session_start();
if(isset($_POST['days']) && isset($_POST['rental'])){
$_SESSION['info'][] = array($_POST['days'] => $_POST['rental']);
}
if(isset($_SESSION['info'])) {
for($i = 0; $i < count($_SESSION['info']); $i++) {
foreach($_SESSION['info'][$i] as $days => $rental){
echo '<p>' . $days . '<br>';
echo $rental . '</p>';
}
}
}
?>
<form action="#" method="post">
Number of Days: <input type="text" name="days" value=""><br/>
Rental rate: <input type="text" name="rental" value=""><br/>
<input type="submit" name="add_rental_rate" value="Add Rental Rate">
</form>
You should read some docs about session:
Post a Comment for "How To Submit A Single Form Value Multiple Times And Store (preserve) Them In An Array Each Time That I Refresh My Page?"