Foros del Web » Programando para Internet » PHP »

formulario para buscar en base de datos un registro

Estas en el tema de formulario para buscar en base de datos un registro en el foro de PHP en Foros del Web. hola a todos soy nuevo en este foro y vengo a buscar ayuda si alguien me puede ayudar estoy haciendo una pagina web en php ...
  #1 (permalink)  
Antiguo 31/03/2012, 13:13
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
formulario para buscar en base de datos un registro

hola a todos soy nuevo en este foro y vengo a buscar ayuda si alguien me puede ayudar estoy haciendo una pagina web en php con base de dato, la cual se encargara de buscar registros de alumnos y me muestre las notas todo mi codigo esta bueno pero tengo un problemita muy pequeño pero no le encuentro la solucion les dejos los codigo aver si me pueden ayudar:

este es el codigo del formulario para realizar la busqueda


<html>
<body>
<form action="index.php" method="post">
<div align="center">
<p align="center" class="Estilo1"><em><strong>nada</strong></em></p>
<p align="center" class="Estilo1"><em><strong>lista</strong></em></p>
<p align="center" class="Estilo1"><em><strong>nombre </strong></em></p>
</div>
<form method="post" action="index.php" />
Cedula del Alumno: <input type="int" name="nomb" size="24" maxlength="24" /><br /><br />
<input type="submit" value="Buscar por Nombre" />
</form>
</form>


<table width="100%" height="132" border="0">
<tr>
<td width="22%">&nbsp;</td>
<td width="58%"><?php include("buscador.php");?></td>
<td width="20%">&nbsp;</td>
</tr>
</table>
</body>
</html>




este es el codigo encargado de buscar en la base de dato




<?php
$nombre = addslashes($_POST['nomb']); // esta es la linea 2 donde esta el error
$conexion = mysql_connect("localhost", "root", "16313024");
mysql_select_db("registro", $conexion);

$queEmp = "SELECT * FROM alumnos WHERE ID='$nombre';" or die ("Error en la consulta");
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if (!$totEmp)
{
echo "Usted no ve Clase con este Profesor";
exit;
}
?>

<style type="text/css">
<!--
body {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 14px;
font-weight: normal;
color: #666666;
text-decoration: none;
padding: 20px;
}
h4 {
color: #CC0000;
}
-->
</style>
</head>
<body>
<h4 class="Estilo2">Informacion Personal</h4>
<?php
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
echo "Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";
echo "Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";
echo "Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";
echo "Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";
echo "Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";
echo "Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";

}
}
?>


bueno al grano el codigo encargado de buscan en la base de dato me da este error:

Notice: Undefined index: nomb in C:\xampp\htdocs\buscador.php on line 2
Usted no ve Clase con este Profesor

anexo que todo funciona correctamente me da los datos que quiero pero lo unico es eso que me sale ese error en la pagina.
  #2 (permalink)  
Antiguo 31/03/2012, 13:32
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: formulario para buscar en base de datos un registro

Si querías encandilar usando ese color y tamaño de letra... lo lograste!!!

Si querías llamar la atención para ver si recibes ayuda más pronta y expedita... esa no es la forma, porque esa práctica es equivalente a gritar como loco.

Sorry, no me enteré de qué iba el tema.
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 31/03/2012, 15:31
Avatar de BLAH !!  
Fecha de Ingreso: septiembre-2003
Ubicación: Región Metropolitana, Santiago, Chile
Mensajes: 706
Antigüedad: 20 años, 7 meses
Puntos: 16
Respuesta: formulario para buscar en base de datos un registro

primero: porque tienes dos veces la etiqueta <FORM> ??, dale algun nombre al formulario
<form name="alumnosform" method=POST action="index.php">

segundo: simpre conectate a la BD antes que todo. Y NO dejes tus claves en el post.
$conexion = mysql_connect("localhost", "USER", "PASS");

tercero: $nombre = addslashes($_POST['nomb']); no uses addslashes, ya que por lo que yo entiendo esta funcion es cuando guardas datos en la bd y no cuando los buscas, ademas solo reemplazara ('), ("), y (back /). Como tu campo addslashes CEDULA, creo que no hay ningun caracter que sea los que te mencione en una cedula.

INTENTA Y ME AVISAS
__________________
Adios ...!!!!
  #4 (permalink)  
Antiguo 31/03/2012, 15:40
 
Fecha de Ingreso: marzo-2012
Ubicación: El Vigia Edo Merida
Mensajes: 147
Antigüedad: 12 años, 1 mes
Puntos: 1
Respuesta: formulario para buscar en base de datos un registro

Utiliza este para ver si te funciona y me avisas hermano

<?php
$nombre = $_POST['nomb']; // esta es la linea 2 donde esta el error
$conexion = mysql_connect("localhost", "root", "16313024");
mysql_select_db("registro", $conexion);

$queEmp = "SELECT * FROM alumnos WHERE ID='$nombre';" or die ("Error en la consulta");
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if (!$totEmp)
{
echo "Usted no ve Clase con este Profesor";
exit;
}
?>

<style type="text/css">
<!--
body {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 14px;
font-weight: normal;
color: #666666;
text-decoration: none;
padding: 20px;
}
h4 {
color: #CC0000;
}
-->
</style>
</head>
<body>
<h4 class="Estilo2">Informacion Personal</h4>
<?php
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
echo "Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";
echo "Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";
echo "Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";
echo "Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";
echo "Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";
echo "Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";

}
}
?>
  #5 (permalink)  
Antiguo 31/03/2012, 15:48
Avatar de ylellan  
Fecha de Ingreso: mayo-2010
Ubicación: en un lugar de Veracruz
Mensajes: 432
Antigüedad: 13 años, 10 meses
Puntos: 36
Respuesta: formulario para buscar en base de datos un registro

corazon, haciendo algo mas basico :

Código HTML:
Ver original
  1. <form action="otra.php" method="post">
  2. No de cedula: <input type="text" name="cedula">
  3. <br>
  4. <input type="submit" name="enviar" value="enviar">
  5. </form>

y la pagina de otra.php

Código PHP:
<?php
if(isset($_POST['enviar'])){
    if(!empty(
$_POST['cedula'])){
    
$cedula=$_POST['cedula'];
    
$conexion mysql_connect("localhost""root""16313024");
    
mysql_select_db("registro"$conexion);

    
$q "SELECT * FROM alumnos WHERE ID='$cedula'";
    
$resEmp mysql_query($q$conexion) or die(mysql_error());
    
$totEmp mysql_num_rows($resEmp);
    if (
$totEmp>0)
    {    
    while (
$rowEmp mysql_fetch_assoc($resEmp)) {
    echo 
"Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";
    echo 
"Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";
    echo 
"Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";
    echo 
"Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";
    echo 
"Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";
    echo 
"Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";
    }
else
{
header("location:index.php");
}


}
else
{
header("location:index.php");
}

}
?>
y haber que sale corazon
  #6 (permalink)  
Antiguo 31/03/2012, 17:10
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: formulario para buscar en base de datos un registro

gracias por la pronta respuesta pruebo y les digo como me fue
  #7 (permalink)  
Antiguo 31/03/2012, 17:12
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: formulario para buscar en base de datos un registro

Cita:
Iniciado por elsaiya Ver Mensaje
Utiliza este para ver si te funciona y me avisas hermano

<?php
$nombre = $_POST['nomb']; // esta es la linea 2 donde esta el error
$conexion = mysql_connect("localhost", "root", "16313024");
mysql_select_db("registro", $conexion);

$queEmp = "SELECT * FROM alumnos WHERE ID='$nombre';" or die ("Error en la consulta");
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if (!$totEmp)
{
echo "Usted no ve Clase con este Profesor";
exit;
}
?>

<style type="text/css">
<!--
body {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 14px;
font-weight: normal;
color: #666666;
text-decoration: none;
padding: 20px;
}
h4 {
color: #CC0000;
}
-->
</style>
</head>
<body>
<h4 class="Estilo2">Informacion Personal</h4>
<?php
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
echo "Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";
echo "Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";
echo "Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";
echo "Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";
echo "Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";
echo "Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";

}
}
?>
meda el mismo error que el mio
  #8 (permalink)  
Antiguo 31/03/2012, 17:16
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: formulario para buscar en base de datos un registro

Cita:
Iniciado por ylellan Ver Mensaje
corazon, haciendo algo mas basico :

Código HTML:
Ver original
  1. <form action="otra.php" method="post">
  2. No de cedula: <input type="text" name="cedula">
  3. <br>
  4. <input type="submit" name="enviar" value="enviar">
  5. </form>

y la pagina de otra.php

Código PHP:
<?php
if(isset($_POST['enviar'])){
    if(!empty(
$_POST['cedula'])){
    
$cedula=$_POST['cedula'];
    
$conexion mysql_connect("localhost""root""16313024");
    
mysql_select_db("registro"$conexion);

    
$q "SELECT * FROM alumnos WHERE ID='$cedula'";
    
$resEmp mysql_query($q$conexion) or die(mysql_error());
    
$totEmp mysql_num_rows($resEmp);
    if (
$totEmp>0)
    {    
    while (
$rowEmp mysql_fetch_assoc($resEmp)) {
    echo 
"Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";
    echo 
"Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";
    echo 
"Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";
    echo 
"Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";
    echo 
"Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";
    echo 
"Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";
    }
else
{
header("location:index.php");
}


}
else
{
header("location:index.php");
}

}
?>
y haber que sale corazon
el codigo otra.php tiene un error en la linea 21
  #9 (permalink)  
Antiguo 31/03/2012, 18:18
Avatar de ylellan  
Fecha de Ingreso: mayo-2010
Ubicación: en un lugar de Veracruz
Mensajes: 432
Antigüedad: 13 años, 10 meses
Puntos: 36
Respuesta: formulario para buscar en base de datos un registro

corazones, problemas con las {}, ups, perdon, asi es a mi manera

Código PHP:
<?php
if(isset($_POST['enviar']))
{
    if(!empty(
$_POST['cedula']))
    {    
        include 
"conexion.php";
        
$cedula=$_POST['cedula']; 
        
conectar();    
            
$q "SELECT * FROM alumnos WHERE ID='$cedula'"
            
$resEmp mysql_query($q) or die(mysql_error()); 
        
desconectar();
            
$totEmp mysql_num_rows($resEmp);
        if(
$totEmp>0)
        {
            while (
$rowEmp mysql_fetch_assoc($resEmp)) 
            { 
                    echo 
"Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>"
                    echo 
"Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>"
                    echo 
"Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>"
                    echo 
"Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>"
                    echo 
"Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>"
                    echo 
"Nota Definitiva: ".$rowEmp['nota_final']."<br></br>"
            }
        }
        else
        {
            
header("location:index.php"); 
        }
    }
    else
    {
        
header("location:index.php"); 
    }    
}
else
{
    
header("location:index.php");     
}
?>
  #10 (permalink)  
Antiguo 31/03/2012, 18:25
Avatar de ylellan  
Fecha de Ingreso: mayo-2010
Ubicación: en un lugar de Veracruz
Mensajes: 432
Antigüedad: 13 años, 10 meses
Puntos: 36
Respuesta: formulario para buscar en base de datos un registro

ha si quieres el archivo de conexion ve aqui, ahi muestro como lo uso casi siempre :p
  #11 (permalink)  
Antiguo 02/04/2012, 07:38
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: formulario para buscar en base de datos un registro

ok probare y te digo como me fue
  #12 (permalink)  
Antiguo 02/04/2012, 08:59
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: formulario para buscar en base de datos un registro

mira hice este como me digiste pero no me arroja resultado la pagina queda en blanco, solo me manda a la pagina de inicio

Código PHP:
<?php
if(isset($_POST['nomb'])) 

    if(!empty(
$_POST['nombre'])) 
    {     






$conexion mysql_connect("localhost""root""16313024");
mysql_select_db("registro"$conexion);

$queEmp "SELECT * FROM alumnos WHERE ID='$nombre';" or die ("Error en la consulta");
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
 
        
desconectar(); 
$totEmp mysql_num_rows($resEmp);


if(
$totEmp>0
        { 
            while (
$rowEmp mysql_fetch_assoc($resEmp))  
            {  
                    echo 
"Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";  
                    echo 
"Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";  
                    echo 
"Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";  
                    echo 
"Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";  
                    echo 
"Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";  
                    echo 
"Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";  
            } 
        } 
        else 
        { 
            
header("location:index.php");  
        } 
    } 
    else 
    { 
        
header("location:index.php");  
    }     

else 

    
header("location:index.php");      

?>

y le cambie la linea 2 a mi codigo y ya no me sale el erro pero me sale tambien la pagina en blanco no me arroja los resultados este es mi codigo


Código PHP:
<?php
$nombre 
= isset($_POST['nomb']); // esta es la linea 2 donde estaba el error
$conexion mysql_connect("localhost""root""16313024");
mysql_select_db("registro"$conexion);

$queEmp "SELECT * FROM alumnos WHERE ID='$nombre';" or die ("Error en la consulta");
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
$totEmp mysql_num_rows($resEmp);
if (!
$totEmp)
{
echo 
"Usted no ve Clase con este Profesor";
exit;
}
?>

<style type="text/css">
<!--
body {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 14px;
font-weight: normal;
color: #666666;
text-decoration: none;
padding: 20px;
}
h4 {
color: #CC0000;
}
-->
</style>
</head>
<body>
<h4 class="Estilo2">Informacion Personal</h4>
<?php 
if ($totEmp0) {
while (
$rowEmp mysql_fetch_assoc($resEmp)) {
echo 
"Nombre: <strong>".$rowEmp['nombre']."</strong><br></br>";
echo 
"Apellidos:<strong>".$rowEmp['apellido']."</strong><br></br>";
echo 
"Nota Primer Lapso: ".$rowEmp['nota1']."<br></br>";
echo 
"Nota Segundo Lapso: ".$rowEmp['nota2']."<br></br>";
echo 
"Nota Tercer Lapso: ".$rowEmp['nota3']."<br></br>";
echo 
"Nota Definitiva: ".$rowEmp['nota_final']."<br></br>";

}
}
?>

Última edición por elkumanes1; 02/04/2012 a las 09:31

Etiquetas: formulario, html, mysql, registro, sql
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 06:18.