Foros del Web » Programando para Internet » PHP »

Insertar registros y mostar en otra pagina

Estas en el tema de Insertar registros y mostar en otra pagina en el foro de PHP en Foros del Web. Necesito que despues de hacer la inserción de registros, mostrar en otra pagina lo que he realizado, esto se haria pasando variables? como se hace? ...
  #1 (permalink)  
Antiguo 31/07/2012, 07:46
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Insertar registros y mostar en otra pagina

Necesito que despues de hacer la inserción de registros, mostrar en otra pagina lo que he realizado, esto se haria pasando variables? como se hace?

este es el codigo de mi pagina:

Código PHP:
<?php require_once('../Connections/conex.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO guia (Remitente, Destinatario) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['Remitente'], "text"),
                       
GetSQLValueString($_POST['Destinatario'], "text"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Remitente:</td>
      <td><input type="text" name="Remitente" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Destinatario:</td>
      <td><input type="text" name="Destinatario" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
  #2 (permalink)  
Antiguo 31/07/2012, 08:12
Avatar de dontexplain  
Fecha de Ingreso: junio-2012
Mensajes: 536
Antigüedad: 11 años, 10 meses
Puntos: 127
Respuesta: Insertar registros y mostar en otra pagina

Una forma es pasando el dato mediante una variable GET usando un header

header("Location: mostrardatos.php?dato="+dato);

y en mostrardatos.php

echo $_GET['dato'];

Un saludo.
__________________
21añero.
HTML/CSS, PHP, JS/jQuery, Mysql; NodeJS/Socket.io (& V8); C++ ; Python (wxpy); Ensamblador.
Músico (clarinetista/pianista) y compositor
  #3 (permalink)  
Antiguo 31/07/2012, 08:48
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Insertar registros y mostar en otra pagina

header("Location: mostrardatos.php?dato="+dato); esto iria en la pagina donde inserto dato cierto? lo declaro en que parte al principio?.


y en la pagiona donde muestro:

echo $_GET['dato'];
  #4 (permalink)  
Antiguo 31/07/2012, 08:58
Avatar de dontexplain  
Fecha de Ingreso: junio-2012
Mensajes: 536
Antigüedad: 11 años, 10 meses
Puntos: 127
Respuesta: Insertar registros y mostar en otra pagina

Cita:
Iniciado por Zota Ver Mensaje
header("Location: mostrardatos.php?dato="+dato); esto iria en la pagina donde inserto dato cierto? lo declaro en que parte al principio?.


y en la pagiona donde muestro:

echo $_GET['dato'];
header("Location: loquesea") lo único que hace es enviar una cabecera location

Se inserta justo donde quieres que el navegador redirija a la nueva página, esto es, al final de la serie de instrucciones. Después de header no puede ir ninguna salida html (echo).

Un saludo.
__________________
21añero.
HTML/CSS, PHP, JS/jQuery, Mysql; NodeJS/Socket.io (& V8); C++ ; Python (wxpy); Ensamblador.
Músico (clarinetista/pianista) y compositor
  #5 (permalink)  
Antiguo 31/07/2012, 09:40
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Insertar registros y mostar en otra pagina

Hice lo que me pediste pero al llevarme a la otra pagina me muestra en blanco

mira no se si lo hice mal

aqui inserto datos


Código PHP:
<?php require_once('../Connections/conex.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO pruebas (Nombre, Apellido) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['Nombre'], "text"),
                       
GetSQLValueString($_POST['Apellido'], "text"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());

  
$insertGoTo "mostrardatos.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header("Location: mostrardatos.php?Nombre="+Nombre);
  
header(sprintf("Location: %s"$insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<p>&nbsp;</p>

<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nombre:</td>
      <td><input type="text" name="Nombre" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Apellido:</td>
      <td><input type="text" name="Apellido" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
aqui muestro

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php echo $_GET['Nombre'];?>
</body>
</html>
  #6 (permalink)  
Antiguo 31/07/2012, 10:16
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Insertar registros y mostar en otra pagina

crea un array de session con esos datos y ya los tienes todos los datos en las paginas que quieras hasta que la destruyas con un simple foreach puedes mostrar los datos despues en otras paginas
  #7 (permalink)  
Antiguo 31/07/2012, 10:24
Avatar de dontexplain  
Fecha de Ingreso: junio-2012
Mensajes: 536
Antigüedad: 11 años, 10 meses
Puntos: 127
Respuesta: Insertar registros y mostar en otra pagina

Haz lo que te dice el compañero de arriba.
__________________
21añero.
HTML/CSS, PHP, JS/jQuery, Mysql; NodeJS/Socket.io (& V8); C++ ; Python (wxpy); Ensamblador.
Músico (clarinetista/pianista) y compositor
  #8 (permalink)  
Antiguo 31/07/2012, 11:37
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Insertar registros y mostar en otra pagina

Gracias por su ayuda, pero soy muy nuevo en esto de php y no se como crearlo, algun tutorial o manuela en lenguahe HUMANO o de nuevos para esto?
  #9 (permalink)  
Antiguo 31/07/2012, 11:45
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Insertar registros y mostar en otra pagina

mejor que los manuales de php ninguno

array

http://php.net/manual/es/language.types.array.php

session

http://es.php.net/manual/es/reserved...es.session.php

foreach

http://es.php.net/manual/es/control-...es.foreach.php

session_start()

http://es.php.net/manual/es/function.session-start.php

esto es todo lo que necesitas saber
  #10 (permalink)  
Antiguo 31/07/2012, 18:31
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Insertar registros y mostar en otra pagina

HE realizado el ejercicio como me dice pero no se que hago mal, no me pasa el valor de las variables se de sesion:

Código PHP:
<?php
session_start
();
   include(
"conex.php");
   
$link=Conectarse();
   
$result=mysql_query("select * from pruebas",$link);
?>s

   <TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
      <TR><TD>&nbsp;Nombre</TD><TD>&nbsp;Apellidos&nbsp;</TD></TR>
<?php      

   
while($row mysql_fetch_array($result)) {
      
printf("<tr><td>&nbsp;%s</td><td>&nbsp;%s&nbsp;</td></tr>"$row["Nombre"],$row["Apellido"]);
   }
   
mysql_free_result($result);
   
mysql_close($link);
   
$_SESSION['Nombre']  = $row["Nombre"];
$_SESSION['Apellido'] = $row["Apellido"];
$_SESSION['time']   = time()-3600;
echo 
'<br /><a href="pagina2.php">página 2</a>';
// O quizás pasar el id de sesión, si fuera necesario
echo '<br /><a href="pagina2.php?' SID '">página 2</a>';
?>

</table>
</body>
</html>

dodne recibo:


Código PHP:
<?php
// pagina2.php
session_start();
echo 
'Bienvenido a la página #2<br />';
echo 
$_SESSION['Nombre'];  // verde
echo $_SESSION['Apellido']; // gato
echo date('Y m d H:i:s'$_SESSION['time']);
// Puede querer usar SID aquí, como hicimos en pagina1.php
echo '<br /><a href="pagina1.php">página 1</a>';
?>
  #11 (permalink)  
Antiguo 31/07/2012, 18:53
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Insertar registros y mostar en otra pagina

en la pagin 2 az un print_r($_SESSION); y reportanos el resultado

en la pagin 1 eso es todo el codigo o hay mas??? lo digo por las etiquetas html body si tienes codigo po encima no va a funcionar session_start(); debes de ponerlo antes de generar cualquier html

te marca algun warning en pagina 2 o 1???

Última edición por webankenovi; 31/07/2012 a las 19:06
  #12 (permalink)  
Antiguo 01/08/2012, 05:15
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Insertar registros y mostar en otra pagina

realize las modificaciones que me diste y en la apgina de mostrarme las variables sigue sin mostrarlas y poniendole el codigo print_r($_SESSION); vota esto:


Bienvenido a la página #2
2012 08 01 05:20:40Array ( [Nombre] => [Apellido] => [time] => 1343812840 )


es decir solo me vota la varibale time, las otras estan vacias.
  #13 (permalink)  
Antiguo 01/08/2012, 09:11
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Insertar registros y mostar en otra pagina

pues si te das cuenta el error no esta en la session ya que esta si llega si no a como guardaste los datos en la session

en la consulta que haces no pasas ningun id entonces si hay mas de un usuario guardado estas

$_SESSION['Nombre'] = $row["Nombre"];
$_SESSION['Apellido'] = $row["Apellido"];

fuera del while no son validas , para un solo usuario no es necesario un while para mas de uno si , y entonces ya hablamos de array de $_SESSION si no te va a ser imposible

metelas dentro del while para mas de uno si no no hace falta, en la consulta pasale una id de ejemplo y ya me cuentas

Última edición por webankenovi; 01/08/2012 a las 09:17

Etiquetas: html, mostar, mysql, registro, registros, sql, variables
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 18:05.