PHP - Buscar y redireccionar en un formulario

 
Vista:
Imágen de perfil de David

Buscar y redireccionar en un formulario

Publicado por David (38 intervenciones) el 09/09/2014 14:49:22
Buen dia,

Quisiera que por favor me ayudaran con una inquietud. Tengo un formulario sencillo que pregunta el numero de identificacion y un boton BUSCAR, cuando le haga clic debe buscar y si existe quiero que me redireccione a un formulario mostrandole sus datos (identificacion, nombres y apellidos) para que los actualice, sino existe que me envie a un formulario vacio para que diligencie los datos.

El buscar lo puedo hacer preguntando si existe o no el N° de documento, mi duda es como puedo hacer para que redireccione a los otros formularios y llevando los datos.

Muchas gracias por su valiosa ayuda.

Saludos
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
sin imagen de perfil
Val: 729
Bronce
Ha aumentado 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

Buscar y redireccionar en un formulario

Publicado por Gonzalo (615 intervenciones) el 09/09/2014 16:38:31
en ambos casos pasa solo el numero de identificacion.

si el numero que pasaste no existe entonces insertas el registro con ese numero en la base de datos, como no hay datos el formato se muestra en blanco.

si el numero que pasaste si existe entonces recupera los datos y el formato se muestra lleno listo para editar.

salu2
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
Imágen de perfil de David

Buscar y redireccionar en un formulario

Publicado por David (38 intervenciones) el 09/09/2014 18:51:53
Hola a todos, a continuacion dejo el codigo que ya funciona:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<form action="result_doc.php" method="post"  name="form1" target="_blank">
<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>N° Cedula</td>
    <td><label for="cedula"></label>
      <input type="text" name="cedula" id="cedula"></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="buscar" id="buscar" value="Enviar"></td>
  </tr>
</table>
</form>

ahora el .php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php require_once('Connections/conexion.php'); ?>
<?php
$cedula=$_POST["cedula"];
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;
}
}
 
$colname_Recordset1 = "-1";
if (isset($_GET['cedula'])) {
  $colname_Recordset1 = $_GET['cedula'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset1 = sprintf("SELECT * FROM docentes WHERE cedula = $cedula", GetSQLValueString($colname_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>Documento sin título</title>
</head>
 
<body>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><label for="textfield">Cedula</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['cedula']; ?>"></td>
      <td><label for="textfield">Nombre</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['nombre']; ?>"></td>
    </tr>
    <tr>
      <td><label for="textfield">Apellido</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['apellido1']; ?>"></td>
      <td><label for="textfield">Apellido 2</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['apellido2']; ?>"></td>
    </tr>
    <tr>
      <td><label for="textfield">Email</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['email']; ?>"></td>
      <td><label for="textfield">Confirmar Email</label></td>
      <td><input type="text" name="textfield" id="textfield"></td>
    </tr>
    <tr>
      <td>Contraseña</td>
      <td><input type="text" name="textfield" id="textfield"></td>
      <td>Confirmar contraseña</td>
      <td><input type="text" name="textfield" id="textfield"></td>
    </tr>
    <tr>
      <td>Departamento</td>
      <td><select title="<?php echo $row_Recordset1['departamento']; ?>"></select></td>
      <td>Ciudad</td>
      <td><select title="<?php echo $row_Recordset1['ciudad']; ?>"></select></td>
    </tr>
    <tr>
      <td>Institucion</td>
      <td colspan="3"><select title="<?php echo $row_Recordset1['institucion']; ?>"></select></td>
    </tr>
 
  </tbody>
  </table>
  <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td><label for="textfield">Grado</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['grado']; ?>"></td>
      <td><label for="textfield">Area</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['area']; ?>"></td>
      <td><label for="textfield">Licencia</label></td>
      <td><input name="textfield" type="text" id="textfield" value="<?php echo $row_Recordset1['licencia']; ?>"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="button" name="button" id="button" value="Enviar"></td>
    </tr>
   </tbody>
</table>
 
<p>&nbsp;</p>
 
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

y el de conexion .php
1
2
3
4
5
6
7
8
9
10
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexion = "localhost";
$database_conexion = "prueba";
$username_conexion = "root";
$password_conexion = "tuclave";
$conexion = mysql_pconnect($hostname_conexion, $username_conexion, $password_conexion) or trigger_error(mysql_error(),E_USER_ERROR);
?>


Saludos y muchas gracias :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar