Foros del Web » Programando para Internet » PHP »

problemas select

Estas en el tema de problemas select en el foro de PHP en Foros del Web. Buenas noches a todos, mi problema es el siguiente tengo 4 hojas 1 donde se ingresa la matricula para iniciar session la 2 me valida ...
  #1 (permalink)  
Antiguo 11/04/2012, 02:38
 
Fecha de Ingreso: noviembre-2011
Ubicación: Paris
Mensajes: 450
Antigüedad: 12 años, 5 meses
Puntos: 7
problemas select

Buenas noches a todos, mi problema es el siguiente tengo 4 hojas 1 donde se ingresa la matricula para iniciar session la 2 me valida la 3 igual pero en la 4 quiero hacer un query que me seleccione los datos de una tabla con la matricula que ingrese en la primera hoja, ya lo he echo pero solo de una pagina a otra, Espero y me puedan ayudar por favor, este es mi codigo:

pag1
Código PHP:
<html>
<
head>

</
head>
<
body>
<
form action="2.php" method="post">
Ingrese su matricula:<input type='text' name='matricula' /><br><br>

<
input type="submit" value="confirmar">
</
form>
</
body>
</
html
pag2
Código PHP:
<?php
$matricula
=$_POST['matricula'];


if(
$matricula)
{
include 
"config.php";

$consulta=mysql_query("SELECT * FROM registrados WHERE matricula='".$matricula."'");
$filas=mysql_fetch_array($consulta);

$matriculabd=$filas['matricula'];
$id=$filas['id'];

if(
$matricula==$matriculabd){

session_start();

$_SESSION['usuario']=$matriculabd;
$_SESSION['id']=$id;






echo 
"

<html>
<head>
<meta http-equiv='REFRESH' content='0 ; url=3.php'>
<script>
alert('Bienvenido');
</script>

</head>
</html>


"
;


}
else{

echo 
"

<html>
<head>
<meta http-equiv='REFRESH' content='0 ; url=index.php'>
<script>
alert('Has ingresado una matricula incorrecta, intente de nuevo!');
</script>

</head>
</html>


"
;

}



}
else{

echo 
"

<html>
<head>
<meta http-equiv='REFRESH' content='0 ; url=index.php'>
<script>
alert('Favor de ingresar su matricula!');
</script>

</head>
</html>


"
;



}

?>
pag3
Código PHP:
<?php
session_start
();
$usuario=$_SESSION['usuario'];
$id=$_SESSION['id'];

if(
$usuario AND $id){
//echo "holaaaaaa"."<a href='cerrarsession.php'>Cerrar</a>";





echo "

<html>
<head>
<meta http-equiv='REFRESH' content='0 ; url=4.php'>
<script>

</script>

</head>
</html>


"
;

}
else{

echo 
"

<html>
<head>
<meta http-equiv='REFRESH' content='0 ; url=index.php'>
<script>
alert('Matricula incorrecta!');
</script>

</head>
</html>


"
;

}
?>
pag4
Código PHP:
<?php
session_start
();


    include 
"config.php";
   
    
$registros=mysql_query("select * from registrados where matricula='$_REQUEST[matricula]'",$conexion) or
    die(
"Problemas en el select:".mysql_error());


if (
$reg=mysql_fetch_array($registros)) 

  echo 
"Nombre:".$reg['nombre']."<br>"
  
  
  

else 

  echo 
"No existe un alumno con ese mail."

mysql_close($conexion); 
?>
  #2 (permalink)  
Antiguo 11/04/2012, 03:44
Avatar de vgonga1986  
Fecha de Ingreso: marzo-2008
Ubicación: País de Pandereta
Mensajes: 1.021
Antigüedad: 16 años, 1 mes
Puntos: 253
Respuesta: problemas select

Buenos días,

Según veo en el código, en la página 2 utilizas la sesión para almacenar la matrícula con esta línea:
Código PHP:
$_SESSION['usuario']=$matriculabd
Luego utilizas este SELECT en la página 4 para acceder a la base de datos:
Código SQL:
Ver original
  1. "select * from registrados where matricula='$_REQUEST[matricula]'"

Has probado a hacer un echo de $_REQUEST[matricula], probablemente no tenga nada y por eso no te hace la consulta. El dato que necesitas lo tienes en la sesión:
$_SESSION['usuario']

Espero que te sirva, un saludo.
__________________
¿Alguna pregunta, duda, acotación, nota, cuestión, reparo, comentario, demanda, crítica, interpretación, objeción, interrogante, discrepancia, observación, réplica, disquisición, apostilla o exégesis?
  #3 (permalink)  
Antiguo 11/04/2012, 11:06
 
Fecha de Ingreso: noviembre-2011
Ubicación: Paris
Mensajes: 450
Antigüedad: 12 años, 5 meses
Puntos: 7
Respuesta: problemas select

Muchas gracias por tu ayuda vgonga1986, lo he resuelto

Saludos!

Etiquetas: html, mysql, registro, select, sql, tabla, usuarios
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 15:19.