Foros del Web » Programando para Internet » PHP »

Insertar y hacer el Select.

Estas en el tema de Insertar y hacer el Select. en el foro de PHP en Foros del Web. Hola, por favor tengo este INSERT: Código PHP: if ((isset( $_POST [ "MM_insert" ])) && ( $_POST [ "MM_insert" ] ==  "form1" )) {    $insertSQL  =  sprintf ( "INSERT INTO usuarios (name, apellidos, dni, telefonos,movil, telefonos3) VALUES ( %s, %s, %s, %s, %s, %s)" ...
  #1 (permalink)  
Antiguo 20/01/2013, 15:22
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Insertar y hacer el Select.

Hola, por favor tengo este INSERT:

Código PHP:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO usuarios (name, apellidos, dni, telefonos,movil, telefonos3) VALUES ( %s, %s, %s, %s, %s, %s)",
                       
                       
GetSQLValueString($_POST['name'], "text"),
                       
GetSQLValueString($_POST['apellidos'], "text"),
                       
GetSQLValueString($_POST['dni'], "text"),
                       
GetSQLValueString($_POST['telefonos'], "int"),
                       
GetSQLValueString($_POST['movil'], "int"),
                       
GetSQLValueString($_POST['telefonos3'], "int"));
                       

   
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());


Y quería saber como hacer el SELECT para recuperar los datos después del INSERT y si esto podría hacerlo en la misma página del INSERT o en otra.

GRACIAS
  #2 (permalink)  
Antiguo 20/01/2013, 15:57
 
Fecha de Ingreso: julio-2012
Mensajes: 22
Antigüedad: 11 años, 9 meses
Puntos: 3
Respuesta: Insertar y hacer el Select.

para mi gusto seria mejor recuperar la información en otra pagina.
  #3 (permalink)  
Antiguo 20/01/2013, 16:09
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Insertar y hacer el Select.

Cita:
Iniciado por tony_la09 Ver Mensaje
para mi gusto seria mejor recuperar la información en otra pagina.
OK, pero entonces primero se hace el formulario se manda a otra página donde se hace el INSERT Y EL SELECT en una segunda página o hay otra forma sin tener que cambiar de páginas.
  #4 (permalink)  
Antiguo 20/01/2013, 16:21
 
Fecha de Ingreso: julio-2012
Mensajes: 22
Antigüedad: 11 años, 9 meses
Puntos: 3
Respuesta: Insertar y hacer el Select.

osea los valores que introduzcas en tu primer formulario, los mandaras a un segundo formulario para que los procese y los guarde, ya si kieres visualizar esos datos guardados tendrias que hacer otros formulario. no se si me explique bien.

Ademas veo que en tu codigo tienes la consulta hecha a el insert, lo cual no comprendo, seria mejor hacer la consulta a la BD que as insertado y ademas no veo que muestres los resultados en ningun lado
  #5 (permalink)  
Antiguo 20/01/2013, 16:30
 
Fecha de Ingreso: julio-2012
Mensajes: 22
Antigüedad: 11 años, 9 meses
Puntos: 3
Respuesta: Insertar y hacer el Select.

Por ejemplo para recuperar una consulta hago algo asi

Código PHP:
Ver original
  1. <?php
  2.  
  3. include ("conexion.php");
  4.  
  5. $tabla = "alumnos";
  6.  
  7. $campo = $_POST['campo'];
  8.  
  9. $consulta = "SELECT * FROM $tabla WHERE (matricula = '$campo' OR nombre = '$campo') ";
  10.  
  11. $resultado = mysql_query ($consulta,$conex);
  12.  
  13. $numrows = mysql_num_rows($resultado);
  14.  
  15. if ($numrows <=0){
  16.  
  17. echo "LA MATRICULA O EL NOMBRE: ".$campo." NO EXISTE<br><br>";
  18. echo "PULSE <a href='frmConsultar_Alumno.php'>AQUI</a> SI DESEAS REALIZAR OTRA CONSULTA.<br><br>";
  19. echo "PULSE <a href='Inicio.php'>AQUI</a> SI DESEA IR A LA PAGINA PRINCIPAL.";
  20. echo "<br><br><br>";
  21. include ("pie.php");
  22. mysql_close($conex);
  23.  
  24. } elseif ($numrows > 0){
  25.  
  26.     $matricula = mysql_result($resultado, 0, "matricula");
  27.     $nombre = mysql_result($resultado, 0, "nombre");
  28.     $app = mysql_result($resultado, 0, "app");
  29.     $apm = mysql_result($resultado, 0, "apm");
  30. }
  31.  
  32. ?>
  33.  
  34. <table align="center" width="750" cellspacing="1" cellpadding="3" border="1" bgcolor="#000000">
  35.     <tr bgcolor="#FFFFFF">
  36.         <th>Matricula</th>
  37.         <th>Nombre</th>
  38.         <th>Apellido Paterno</th>
  39.         <th>Apellido Materno</th>
  40.     </tr>
  41.     <tr align="center" bgcolor="#FFFFFF">
  42.             <td id="estilo"><?php echo $matricula; ?></td>
  43.             <td id="estilo"><?php echo $nombre; ?></td>
  44.             <td id="estilo"><?php echo $app; ?></td>
  45.             <td id="estilo"><?php echo $apm; ?></td>
  46.     </tr>
  47. </table>
  48. <br><br>
  49. <p>PULSE <a href="frmConsultar_alumno.php">AQUI</a> SI DESEA HACER OTRA CONSULTA.</p><br>
  50. <p>PULSE <a href="Inicio.php">AQUI</a> SI DESEA IR A LA PAGINA PRINCIPAL.</p>
  51.              <br><br><br>
  52. </div>
  #6 (permalink)  
Antiguo 21/01/2013, 09:49
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Insertar y hacer el Select.

Cita:
Iniciado por tony_la09 Ver Mensaje
Por ejemplo para recuperar una consulta hago algo asi

Código PHP:
Ver original
  1. <?php
  2.  
  3. include ("conexion.php");
  4.  
  5. $tabla = "alumnos";
  6.  
  7. $campo = $_POST['campo'];
  8.  
  9. $consulta = "SELECT * FROM $tabla WHERE (matricula = '$campo' OR nombre = '$campo') ";
  10.  
  11. $resultado = mysql_query ($consulta,$conex);
  12.  
  13. $numrows = mysql_num_rows($resultado);
  14.  
  15. if ($numrows <=0){
  16.  
  17. echo "LA MATRICULA O EL NOMBRE: ".$campo." NO EXISTE<br><br>";
  18. echo "PULSE <a href='frmConsultar_Alumno.php'>AQUI</a> SI DESEAS REALIZAR OTRA CONSULTA.<br><br>";
  19. echo "PULSE <a href='Inicio.php'>AQUI</a> SI DESEA IR A LA PAGINA PRINCIPAL.";
  20. echo "<br><br><br>";
  21. include ("pie.php");
  22. mysql_close($conex);
  23.  
  24. } elseif ($numrows > 0){
  25.  
  26.     $matricula = mysql_result($resultado, 0, "matricula");
  27.     $nombre = mysql_result($resultado, 0, "nombre");
  28.     $app = mysql_result($resultado, 0, "app");
  29.     $apm = mysql_result($resultado, 0, "apm");
  30. }
  31.  
  32. ?>
  33.  
  34. <table align="center" width="750" cellspacing="1" cellpadding="3" border="1" bgcolor="#000000">
  35.     <tr bgcolor="#FFFFFF">
  36.         <th>Matricula</th>
  37.         <th>Nombre</th>
  38.         <th>Apellido Paterno</th>
  39.         <th>Apellido Materno</th>
  40.     </tr>
  41.     <tr align="center" bgcolor="#FFFFFF">
  42.             <td id="estilo"><?php echo $matricula; ?></td>
  43.             <td id="estilo"><?php echo $nombre; ?></td>
  44.             <td id="estilo"><?php echo $app; ?></td>
  45.             <td id="estilo"><?php echo $apm; ?></td>
  46.     </tr>
  47. </table>
  48. <br><br>
  49. <p>PULSE <a href="frmConsultar_alumno.php">AQUI</a> SI DESEA HACER OTRA CONSULTA.</p><br>
  50. <p>PULSE <a href="Inicio.php">AQUI</a> SI DESEA IR A LA PAGINA PRINCIPAL.</p>
  51.              <br><br><br>
  52. </div>
Gracias.

Etiquetas: mysql, select, sql, 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 10:01.