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>';
}
}
}
?><formaction="#"method="post">
Number of Days: <inputtype="text"name="days"value=""><br/>
Rental rate: <inputtype="text"name="rental"value=""><br/><inputtype="submit"name="add_rental_rate"value="Add Rental Rate"></form>
You should read some docs about session:
http://php.net/manual/en/intro.session.php
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?"