This is what I got.
formulario.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title> Surveys </title>
</head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<body>
<form action="main2.php" method="post">
Number of Surveys <input type="number" name="number">
<input type="submit" value="Send"/>
</form>
</body>
</html>
main2.php
<html>
<body>
<?
function Survey($number){
if($number > 0){
$a = 1;
while ($a <= $number){ ?>
<h2>Survey for person number <? echo $a;?></h2>
<form action="resultados.php" method="post">
Age <input type="number" name="age"/> <br><br>
Genre <br><br>
<input type="radio" name="male" value="6"/> Male <br>
<input type="radio" name="female" value="7"/> Female <br><br>
Marital Status <br><br>
<input type="radio" name="single" value="1"/> Single <br>
<input type="radio" name="married" value="2"/> Married <br>
<input type="radio" name="divorced" value="3"/> Divorced <br>
<input type="radio" name="free" value="4"/> Free Union <br>
<input type="radio" name="widowed" value="5"/> Widowed <br><br>
<?
$a = $a + 1;
}
}
}
echo Survey($_POST['number']);
?>
<input type="submit" value="Send"/>
</form>
</body>
</html>
resultados.php
<?
function Calculate($age){
$array_of_ages = array();
$array_of_ages[] = $age;
var_dump($array_of_ages);
}
echo Calcular($_POST['age']);
?>
I want to create a little survey, so in the "formulario.php" file I select an amount of people to go on "main2.php" and create the survey for each. For example, if I select 3 persons, what "main2.php" code should do is to create 3 surveys, one after another, in the same page with only a "submit" buttom. Then, when I "fill all the surveys and press the submit buttom what I'm trying to do with "resultados.php" is to get all the data gathered from those forms and do some stuff like, counting how many people is married or divorced, an average of age in women and men, etc... and show them, after I press "Send".
The problem is that I'm stuck and I don't have any clue on how to do it. I've searched about in ways to catch the info like, arrays, loops, but none of it works. As you can see, I created "resultados.php" where I would supposely show the info processed but no luck.
Depending on which number I select in the first .php file, the "while" in the "main2.php" creates the amount of surveys suggested, but I don't know if it's the right way to do it, according for what I want to reach.
I'll appreciate any help on this. I just started to learn PHP this week and I'm frustrated now because I can't figure out how to solve it by my own.
PD: Sorry for my english, not my native language.