Foros del Web » Programando para Internet » PHP »

PHP- Variables de sesion

Estas en el tema de PHP- Variables de sesion en el foro de PHP en Foros del Web. Hola!! Tengo que hacer una aplicación que me registre los nuevos alumnos de un instituto. Puedo acceder a través de un menu a las diferentes ...
  #1 (permalink)  
Antiguo 26/10/2013, 07:01
 
Fecha de Ingreso: octubre-2013
Ubicación: Alicante- ESPAÑA
Mensajes: 7
Antigüedad: 10 años, 6 meses
Puntos: 0
Pregunta PHP- Variables de sesion

Hola!!

Tengo que hacer una aplicación que me registre los nuevos alumnos de un instituto.
Puedo acceder a través de un menu a las diferentes páginas. El problema es el siguiente:

Cuando selecciono agregar alumno, me sale un formulario que me pide sus datos personales, curso ... que tengo que guardar en un array multidimensional llamado alumnos.

lo guardo mediante: $alumnos[]=array("nombre"=>$nombre, "curso" => $curso...
y se lo asigno a una variable de sesion, ya que luego cuando pinche en mostrar alumnos debe de salirme un listado. $_SESSION['alum']=$alumnos

Si añado alumno y justo despues doy a mostrar alumnos el resultado es correcto.
Si añado dos alumnos seguidos, no me guarda el primero sino que solo añado el segundo.

¿Cómo puedo guardar los dos?
  #2 (permalink)  
Antiguo 26/10/2013, 07:12
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 2 meses
Puntos: 96
Respuesta: PHP- Variables de sesion

$_SESSION['alum'][]=$alumnos
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #3 (permalink)  
Antiguo 26/10/2013, 07:53
 
Fecha de Ingreso: octubre-2013
Ubicación: Alicante- ESPAÑA
Mensajes: 7
Antigüedad: 10 años, 6 meses
Puntos: 0
Pregunta Respuesta: PHP- Variables de sesion

He estado probando, ahora me muestra los dos alumnos nuevos si doy a listar.

Pero si vuelvo a dar a agregar un nuevo alumno y cuando vuelvo a listar me repite los 2 primeros dos veces, creo que es porque vuelve a mostrar otra vez todo y me lo añade a lo que ya estaba listado anteriormente.

Muchas gracias!!!!!!!
  #4 (permalink)  
Antiguo 26/10/2013, 08:11
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 2 meses
Puntos: 96
Respuesta: PHP- Variables de sesion

Si nos mueatras el codigo sera mejor
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #5 (permalink)  
Antiguo 26/10/2013, 11:20
 
Fecha de Ingreso: octubre-2013
Ubicación: Alicante- ESPAÑA
Mensajes: 7
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: PHP- Variables de sesion

únicamente tengo un print_r para mostrar el array.
  #6 (permalink)  
Antiguo 26/10/2013, 12:14
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 2 meses
Puntos: 96
Respuesta: PHP- Variables de sesion

Muestras el codigo del formulario y donde recibes los datos, si quieres que te ayuden, pon los codigos, ya que no somos adivinos.
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #7 (permalink)  
Antiguo 26/10/2013, 13:35
 
Fecha de Ingreso: octubre-2013
Ubicación: Alicante- ESPAÑA
Mensajes: 7
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: PHP- Variables de sesion

Cita:
Iniciado por SkAr88 Ver Mensaje
Muestras el codigo del formulario y donde recibes los datos, si quieres que te ayuden, pon los codigos, ya que no somos adivinos.

aniadir.php

<?php
include('head.php');
include('menu.php');

$mostrar='
<form action="aniadir2.php" method="post"> <BR>

<table align="center" border="1">
<tr>
<td>Nombre:</td><td><input type="text" name=nombre></td>
</tr>
<tr>
<td>Apellidos:</td><td><input type="text" name=apellidos></td>
</tr>
<tr>
<td>Teléfono:</td><td><input type="text" name=telefono></td>
</tr>
<tr>
<td>Curso:</td><td><input type="text" name=curso></td>
</tr>
<tr>
</tr>
<tr>
<td>Madre:</td><td><input type="text" name=madre></td>
</tr>
<tr>
</tr>
<tr>
<td>Padre:</td><td><input type="text" name=padre></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name ="añadir" value="añadir"></td>
</tr>
</table>
</form>
';
echo $mostrar;



[COLOR="rgb(154, 205, 50)"]Anadir2[/COLOR]

include('head.php');
include('menu.php');
session_start();
if (isset($_POST['añadir'])){

$nombre=$_POST['nombre'];
$apellidos=$_POST['apellidos'];
$telefono=$_POST['telefono'];
$curso=$_POST['curso'];
$madre=$_POST['madre'];
$padre=$_POST['padre'];

$alumnos=array(array('Nombre'=>'A', 'Apellidos'=>'A', 'Telefono'=>'A', 'Curso'=>'A', 'Madre'=>'A', 'Padre'=>'B'),
array('Nombre'=>'B', 'Apellidos'=>'B', 'Telefono'=>'B', 'Curso'=>'B','Madre'=>'A', 'Padre'=>'B'));

$alumnos[]=array('Nombre'=> $nombre,'Apellidos'=>$apellidos, 'Telefono'=>$telefono, 'Curso'=>$curso,'Madre'=>$madre, 'Padre'=>$padre);



$_SESSION['alumnos'][]=$alumnos;

echo' <H3> ALUMNO CORRECTO </H3>';


};

[COLOR="rgb(154, 205, 50)"]mostrar[/COLOR]

include('head.php');
include('menu.php');
session_start();

$al=$_SESSION['alumnos'];
print_r ($al);
  #8 (permalink)  
Antiguo 26/10/2013, 14:46
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 2 meses
Puntos: 96
Respuesta: PHP- Variables de sesion

Despues de
Código PHP:
Ver original
  1. $_SESSION['alumnos'][]=$alumnos;
Haz esto
Código PHP:
Ver original
  1. var_dump($_SESSION['alumnos'];
Y muestra lo que te.devuelve
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #9 (permalink)  
Antiguo 26/10/2013, 16:03
 
Fecha de Ingreso: octubre-2013
Ubicación: Alicante- ESPAÑA
Mensajes: 7
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: PHP- Variables de sesion

Cita:
Iniciado por SkAr88 Ver Mensaje
Despues de
Código PHP:
Ver original
  1. $_SESSION['alumnos'][]=$alumnos;
Haz esto
Código PHP:
Ver original
  1. var_dump($_SESSION['alumnos'];
Y muestra lo que te.devuelve
Cuando inserto el primer alumno:
array (size=1)
0 =>
array (size=3)
0 =>
array (size=6)
'Nombre' => string 'A' (length=1)
'Apellidos' => string 'A' (length=1)
'Telefono' => string 'A' (length=1)
'Curso' => string 'A' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'B' (length=1)
1 =>
array (size=6)
'Nombre' => string 'B' (length=1)
'Apellidos' => string 'B' (length=1)
'Telefono' => string 'B' (length=1)
'Curso' => string 'B' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'B' (length=1)
2 =>
array (size=6)
'Nombre' => string 'A' (length=1)
'Apellidos' => string 'A' (length=1)
'Telefono' => string 'A' (length=1)
'Curso' => string 'A' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'A' (length=1)

Muestro la lista de alumnos:
Array ( [0] => Array ( [0] => Array ( [Nombre] => A [Apellidos] => A [Telefono] => A [Curso] => A [Madre] => A [Padre] => B ) [1] => Array ( [Nombre] => B [Apellidos] => B [Telefono] => B [Curso] => B [Madre] => A [Padre] => B ) [2] => Array ( [Nombre] => A [Apellidos] => A [Telefono] => A [Curso] => A [Madre] => A [Padre] => A ) ) )

INSERTO OTRO ALUMNO

array (size=2)
0 =>
array (size=3)
0 =>
array (size=6)
'Nombre' => string 'A' (length=1)
'Apellidos' => string 'A' (length=1)
'Telefono' => string 'A' (length=1)
'Curso' => string 'A' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'B' (length=1)
1 =>
array (size=6)
'Nombre' => string 'B' (length=1)
'Apellidos' => string 'B' (length=1)
'Telefono' => string 'B' (length=1)
'Curso' => string 'B' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'B' (length=1)
2 =>
array (size=6)
'Nombre' => string 'A' (length=1)
'Apellidos' => string 'A' (length=1)
'Telefono' => string 'A' (length=1)
'Curso' => string 'A' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'A' (length=1)
1 =>
array (size=3)
0 =>
array (size=6)
'Nombre' => string 'A' (length=1)
'Apellidos' => string 'A' (length=1)
'Telefono' => string 'A' (length=1)
'Curso' => string 'A' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'B' (length=1)
1 =>
array (size=6)
'Nombre' => string 'B' (length=1)
'Apellidos' => string 'B' (length=1)
'Telefono' => string 'B' (length=1)
'Curso' => string 'B' (length=1)
'Madre' => string 'A' (length=1)
'Padre' => string 'B' (length=1)
2 =>
array (size=6)
'Nombre' => string 'C' (length=1)
'Apellidos' => string 'C' (length=1)
'Telefono' => string 'C' (length=1)
'Curso' => string 'C' (length=1)
'Madre' => string 'C' (length=1)
'Padre' => string 'C' (length=1)

MUESTRO LA LISTA DE ALUMNOS DE NUEVO

Array ( [0] => Array ( [0] => Array ( [Nombre] => A [Apellidos] => A [Telefono] => A [Curso] => A [Madre] => A [Padre] => B ) [1] => Array ( [Nombre] => B [Apellidos] => B [Telefono] => B [Curso] => B [Madre] => A [Padre] => B ) [2] => Array ( [Nombre] => A [Apellidos] => A [Telefono] => A [Curso] => A [Madre] => A [Padre] => A ) ) [1] => Array ( [0] => Array ( [Nombre] => A [Apellidos] => A [Telefono] => A [Curso] => A [Madre] => A [Padre] => B ) [1] => Array ( [Nombre] => B [Apellidos] => B [Telefono] => B [Curso] => B [Madre] => A [Padre] => B ) [2] => Array ( [Nombre] => C [Apellidos] => C [Telefono] => C [Curso] => C [Madre] => C [Padre] => C ) ) )


Necesito que actualice los campos nuevos a la hora de listar unicamente. Gracias

Etiquetas: ayuda!!, sesiones_en_php, variablesphp
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:47.