2
Good Afternoon.
I am trying to create a form whose data will be stored in an array and should be displayed on another page when the people’s registration is finalized. I’m trying to do this with SESSION, however, I believe I’m not being able to pass the data from the form to the vector. No data is displayed on the display page.
My page 1:
<?php
session_start();
$aluno = array();
$_SESSION['cadastro'] = $aluno;
?>
<form action="cadastroS.php"method="POST">
<input type="text" name="nome" placeholder="Nome Completo"></br>
<input type="number" name="ra" placeholder="RA"></br>
<select name="gender">
<option value="Masculino">
<option value="Feminino">
<option value="Outro">
</select></br>
<input type="number" name="idade" min="1" max="99" placeholder="Idade"></br>
<input type="text" name="endereco" placeholder="Endereço"></br>
<input type="tel" name="telefone" placeholder="Telefone"></br>
<input type="email" name="email" placeholder="email"></br></br>
<input type="submit" name="cadastrar" value="Cadastrar">
</form>
<?php
if(!isset($_SESSION['cadastro'])){
array_push(
$_SESSION['cadastro'],
$_REQUEST['nome'],
$_REQUEST["ra"],
$_REQUEST["gender"],
$_REQUEST["idade"],
$_REQUEST["endereco"],
$_REQUEST["telefone"],
$_REQUEST["email"]
);
}
?>
page 2(display registered persons):
<?php
session_start();
foreach ($_SESSION['cadastro'] as $key => $value) {
echo $key .':' . $value, '<br>';
}
?>
Does anyone know what it can be?
You are starting the session where you store the data in $_SESSION ?
– AnthraxisBR
Yes. On both pages I am declaring "session_start();"
– Jefferson Mendes
Do a test like this: var_dump($_REQUEST) before trying to save in the $_SESSION array and check if you are receiving the data, and if you received it, then try: $_SESSION['register']['name'] = $_REQUEST['name'] and see if this field has this value on page 2
– AnthraxisBR
This var_dump test was on the 'cadastros.php' page with var_dump($_REQUEST), is that it ? NOTE: the file that Open in the session, is the same registration name ? with capital S ?
– AnthraxisBR
I did the checks and, with the commands you passed and now is displaying the data on page 2, but displays only the last data entry. I tried using push($_SESSION['registration'], $_REQUEST['name'], ... $_REQUEST["email"]); to add new entries, but only the last one returns.
– Jefferson Mendes
You want it to store a different session every time you submit the form and store all that are sent?
– AnthraxisBR
All registered must be displayed at once after.
– Jefferson Mendes