Hi,
I've created an html form to increase information in an Array, but each time a press the form button, the value of the array is reset.
How can I do to set the value in the array?
There's my example:
<html>
<body>
<form method="post">
<p>First Name: <input type="text" name="firstname"/>
<p>Age: <input type="text" name="age"/>
<p>City: <input type="text" name="city"/>
<input type="submit" value="Send" /></p>
</form>
</body>
<?php
$people = array
(
array("Joe",0,0),
array("Jack",0,0),
array("John",0,0),
array("Mary",0,0)
);
$i=0;
while ($i<=4)
{
if (isset($_POST["firstname"]) and isset($_POST["age"]) and isset($_POST["city"]))
{
if ($_POST["firstname"]=="Joe")
{
$people[0][1]=$_POST["age"];
$people[0][2]=$_POST["city"];
}
if ($_POST["firstname"]=="Jack")
{
$people[1][1]=$_POST["age"];
$people[1][2]=$_POST["city"];
}
if ($_POST["firstname"]=="John")
{
$people[2][1]=$_POST["age"];
$people[2][2]=$_POST["city"];
}
if ($_POST["firstname"]=="Mary")
{
$people[3][1]=$_POST["age"];
$people[3][2]=$_POST["city"];
}
}
$i++;
}
echo("<table><table border='1'>");
echo("<tr><th colspan='3'>People</th></tr>");
echo("<tr><th>Name</th><th>Age</th><th>City</th></tr>");
for ($i=0;$i<=3;$i++)
{
echo("<tr><td align=center>".$people[$i][0]."</td><td align=center>".$people[$i][1]."</td><td align=center>".$people[$i][2]."</td></tr>");
}
?>
</table>
</html>