Could anyone explain me how to solve the following:
function GetSetClearForm(){
$person = array('firstname' => $_POST["fname"], 'lastname' => $_POST["lname"],'age' => $_POST["age"] ,'city' => $_POST["city"] ,'zipcode' => $_POST["zcode"],'address' => $_POST["address"]);
print_r($person);
$personlist = array();
array_push($personlist,$person);
print_r($personlist);
return $personlist;
}
When the print_r($personlist);
has ran I get the following output:
Array (
[0] => Array (
[firstname] => 2
[lastname] => 2
[age] => 2
[city] => 2
[zipcode] => 2
[address] => 2
)
)
(filled in all textboxes with "2").
This is ok at this point, but whenever I fill in another one I get this output:
Array (
[0] => Array (
[firstname] => 1
[lastname] => 1
[age] => 1
[city] => 1
[zipcode] => 1
[address] => 1
)
)
(filled in all textboxes with "1").
So instead of creating another person on a new index (index[1]
) it replaces index[0]
with a new person and deletes the older one. I dont want it do delete it I want to get a list full of people. I think it has to do with the array_push
but I am not sure I hope anyone could help me out here.
EDIT:
Added the index.php:
<form action="check.php" method="POST">
<table>
<tr><td>First name</td><td><input type="text" name="fname"></td></tr>
<tr><td>Last name</td><td><input type="text" name="lname"></td></tr>
<tr><td>Age</td><td><input type="text" name="age"></td></tr>
<tr><td>City</td><td><input type="text" name="city"></td></tr>
<tr><td>Zipcode</td><td><input type="text" name="zcode"></td></tr>
<tr><td>Adress</td><td><input type="text" name="address"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
Added the check.php
<?php
include("functions.php");
$personlist = array();
$personlist[] = GetSetClearForm();
print_r($personlist);
?>