PHP - Consultas en php

 
Vista:
sin imagen de perfil

Consultas en php

Publicado por John Alberto (4 intervenciones) el 04/04/2014 04:57:08
Hola, necesito ayuda con una consulta en php.
Tengo una pagina de consulta en html y envía la consulta a una pagina en php y posteriormente a una de modificar. Cuando no dígito ningún dato y le doy al botón me consulta y me muestre vació. La idea es que cuando consulte un numero de identificación que no este en la base de datos me diga que no esta y no me deje continuar.
Seria de mucha ayuda cualquier colaboración.

código de la Consulta html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Consultar Preinscripcion</title>
</head>
 
<body>
<form action="Consulta.php?documento=documento" method="get" name="form1" id="form1">
  <label for="Identificacion"></label>
  <input type="text" name="Identificacion" id="Identificacion">
  <input type="submit" name="consultar" id="consultar" value="Consultar">
</form>
</body>
</html>

Codigo de la pagina donde hace la consulta a la base de datos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php require_once('Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$vardocumento_Recordset1 = "-1";
 
if(isset($_GET['Identificacion'])) {
 $vardocumento_Recordset1 = $_GET['Identificacion'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset1 = sprintf("SELECT Identificacion, Primer_Nombre, Primer_Apellido FROM aprendiz WHERE Identificacion = %s", GetSQLValueString($vardocumento_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Consulta Formulario</title>
</head>
 
<body>
<form name="form1" method="post" action="">
  <table width="369" border="1">
    <tr>
      <td>Numer de Documento</td>
      <td><?php echo $row_Recordset1['Identificacion']; ?></td>
    </tr>
    <tr>
      <td>Primer Nombre</td>
      <td><?php echo $row_Recordset1['Primer_Nombre']; ?></td>
    </tr>
    <tr>
      <td>Primer Apellido</td>
      <td><?php echo $row_Recordset1['Primer_Apellido']; ?></td>
    </tr>
    <tr>
      <td colspan="2"><a href="modificar.php?Identificacion=<?php echo $row_Recordset1["Identificacion"];?>">modificar</a></td>
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Consultas en php

Publicado por xve (6935 intervenciones) el 04/04/2014 13:12:06
Hola John, una manera seria algo así:

1
2
3
4
5
6
7
8
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
if(!$Recordset1)
{
    echo "no hay registros";
}else{
    ...
    el resto de tu codigo
    ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Consultas en php

Publicado por John Alberto (4 intervenciones) el 04/04/2014 23:39:20
Lo estructure así pero no me sirve, fue echo en: Dw

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$vardocumento_Recordset1 = "-1";
 
if(isset($_GET['Identificacion'])) {
 $vardocumento_Recordset1 = $_GET['Identificacion'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset1 = sprintf("SELECT Identificacion, Primer_Nombre, Primer_Apellido FROM aprendiz WHERE Identificacion = %s", GetSQLValueString($vardocumento_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
if(!$Recordset1)
{
 echo "no hay registros";
}else{	
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
}
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar