Foros del Web » Programando para Internet » PHP »

Pasar variable después hacer un update.

Estas en el tema de Pasar variable después hacer un update. en el foro de PHP en Foros del Web. Hola, buenas tardes quisiera saber como puedo hacer para después de hacer un update de un formulario me llevara una variable llamada num_aparato a otra ...
  #1 (permalink)  
Antiguo 29/11/2012, 10:17
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
Pasar variable después hacer un update.

Hola, buenas tardes quisiera saber como puedo hacer para después de hacer un update de un formulario me llevara una variable llamada num_aparato a otra pagina llamada menu3.php.En el interior del cod lo detallo.

Aquí el cod:

Código Javascript:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  40.   $updateSQL = sprintf("UPDATE ap_usuarios SET MODELO=%s, MARCA=%s, APARATO=%s, COD_APARATO=%s, GRUPO=%s, NUM_PRODUCTO=%s, REVISION=%s, FD=%s, NUM_SERIE=%s, DISTRIBUIDOR=%s, ASEGURADORA=%s, FECHA_COMPRA=%s, INICIO_GARANTIA=%s, FIN_GARANTIA=%s WHERE NUM_APARATO=%s",
  41.                        GetSQLValueString($_POST['MODELO'], "text"),
  42.                        GetSQLValueString($_POST['MARCA'], "text"),
  43.                        GetSQLValueString($_POST['APARATO'], "text"),
  44.                        GetSQLValueString($_POST['COD_APARATO'], "text"),
  45.                        GetSQLValueString($_POST['GRUPO'], "text"),
  46.                        GetSQLValueString($_POST['NUM_PRODUCTO'], "text"),
  47.                        GetSQLValueString($_POST['REVISION'], "text"),
  48.                        GetSQLValueString($_POST['FD'], "text"),
  49.                        GetSQLValueString($_POST['NUM_SERIE'], "text"),
  50.                        GetSQLValueString($_POST['DISTRIBUIDOR'], "text"),
  51.                        GetSQLValueString($_POST['ASEGURADORA'], "text"),
  52.                        GetSQLValueString($_POST['FECHA_COMPRA'], "date"),
  53.                        GetSQLValueString($_POST['INICIO_GARANTIA'], "date"),
  54.                        GetSQLValueString($_POST['FIN_GARANTIA'], "date"),
  55.                        GetSQLValueString($_POST['NUM_APARATO'], "int"));
  56.  
  57.   mysql_select_db($database_conexion, $conexion);
  58.   $Result1 = mysql_query($updateSQL, $conexion) or die(mysql_error());
  59.  
  60.  $updateGoTo = "menu3.php";///Aquí es donde quiero que me lleve después del update con la variable $num_aparato/////
  61.   if (isset($_SERVER['QUERY_STRING'])) {
  62.     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
  63.     $updateGoTo .= $_SERVER['QUERY_STRING'];
  64.   }
  65.   header(sprintf("Location: %s", $updateGoTo));
  66. }
  67. $num_aparato=$_GET['ID'];
  68. mysql_select_db($database_conexion, $conexion);
  69. $query_Recordset1 = "SELECT * FROM ap_usuarios where num_aparato = '$num_aparato'";
  70. $Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
  71. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  72. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  73. ?>
  74. <form method="post" name="form3" action="<?php echo $editFormAction; ?>">
  75. <table width="100%">
  76.   <tr>
  77.     <td>Aparato</td>
  78.     <td><input name="APARATO" type="text" value="<?php echo $row_Recordset1['APARATO']; ?>" /></td>
  79.     <td>Modelo</td>
  80.     <td><input name="MODELO" type="text" value="<?php echo $row_Recordset1['MODELO']; ?>" /></td>
  81.     <td>NºSerie</td>
  82.     <td><input name="NUM_SERIE" type="text" value="<?php echo $row_Recordset1['NUM_SERIE']; ?>" /></td>
  83.   </tr>
  84.   <tr>
  85.     <td>Marca</td>
  86.     <td><input name="MARCA" type="text" value="<?php echo $row_Recordset1['MARCA']; ?>" /></td>
  87.     <td>Cod/12Nc</td>
  88.     <td><input name="NUM_PRODUCTO" type="text" value="<?php echo $row_Recordset1['NUM_PRODUCTO']; ?>" /></td>
  89.     <td>Revisión</td>
  90.     <td><input name="REVISION" type="text" /></td>
  91.   </tr>
  92.   <input type="hidden" name="MM_update" value="form3">
  93.   <input type="hidden" name="NUM_APARATO" value="<?php echo $row_Recordset1['NUM_APARATO']; ?>">
  94.   </table>
  95.   </form>
  96. <?php
  97. mysql_free_result($Recordset1);
  98. ?>

Gracias y un saludo.
  #2 (permalink)  
Antiguo 29/11/2012, 10:25
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 9 meses
Puntos: 194
Respuesta: Pasar variable después hacer un update.

Si solo quieres pasarle esa variable, con hacer algo como esto seria suficiente

Código PHP:
Ver original
  1. $updateGoTo = "menu3.php?num_aparato=$num_aparato";
  2. header("Location:$updateGoTo");
No me canso de repetir este error, es importante que siempre hagas un exit luego de cualquier location, php continua ejecutando la página luego de redirigir aunque no lo veas
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #3 (permalink)  
Antiguo 29/11/2012, 11:21
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: Pasar variable después hacer un update.

Gracias, por contestar. Me he equivocado y la variable era NUM_USUARIO que está mas abajo en el formulario que hago (antes se me olvido incluirla) que está en el select.
Lo vuelvo a poner:

Código Javascript:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  40.   $updateSQL = sprintf("UPDATE ap_usuarios SET MODELO=%s, MARCA=%s, APARATO=%s, COD_APARATO=%s, GRUPO=%s, NUM_PRODUCTO=%s, REVISION=%s, FD=%s, NUM_SERIE=%s, DISTRIBUIDOR=%s, ASEGURADORA=%s, FECHA_COMPRA=%s, INICIO_GARANTIA=%s, FIN_GARANTIA=%s WHERE NUM_APARATO=%s",
  41.                        
  42.                        GetSQLValueString($_POST['MODELO'], "text"),
  43.                        GetSQLValueString($_POST['MARCA'], "text"),
  44.                        GetSQLValueString($_POST['APARATO'], "text"),
  45.                        GetSQLValueString($_POST['COD_APARATO'], "text"),
  46.                        GetSQLValueString($_POST['GRUPO'], "text"),
  47.                        GetSQLValueString($_POST['NUM_PRODUCTO'], "text"),
  48.                        GetSQLValueString($_POST['REVISION'], "text"),
  49.                        GetSQLValueString($_POST['FD'], "text"),
  50.                        GetSQLValueString($_POST['NUM_SERIE'], "text"),
  51.                        GetSQLValueString($_POST['DISTRIBUIDOR'], "text"),
  52.                        GetSQLValueString($_POST['ASEGURADORA'], "text"),
  53.                        GetSQLValueString($_POST['FECHA_COMPRA'], "date"),
  54.                        GetSQLValueString($_POST['INICIO_GARANTIA'], "date"),
  55.                        GetSQLValueString($_POST['FIN_GARANTIA'], "date"),
  56.                        GetSQLValueString($_POST['NUM_APARATO'], "int"));
  57.  
  58.   mysql_select_db($database_conexion, $conexion);
  59.   $Result1 = mysql_query($updateSQL, $conexion) or die(mysql_error());
  60.  
  61.   $updateGoTo = "menu3.php?id=$NUM_USUARIO"; ///Lo estoy haciendo así pero sigue sin funcionar////
  62.   header("Location:$updateGoTo");
  63.   exit;
  64. }
  65. $num_aparato=$_GET['ID'];
  66. mysql_select_db($database_conexion, $conexion);
  67. $query_Recordset1 = "SELECT * FROM ap_usuarios where num_aparato = '$num_aparato'";
  68. $Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
  69. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  70. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  71. ?>
  72. <form method="post" name="form3" action="<?php echo $editFormAction; ?>">
  73. <table width="100%">
  74.   <tr>
  75.     <td>Aparato</td>
  76.     <td><input name="APARATO" type="text" value="<?php echo $row_Recordset1['APARATO']; ?>" /></td>
  77.     <td>Modelo</td>
  78.     <td><input name="MODELO" type="text" value="<?php echo $row_Recordset1['MODELO']; ?>" /></td>
  79.     <td>NºSerie</td>
  80.     <td><input name="NUM_SERIE" type="text" value="<?php echo $row_Recordset1['NUM_SERIE']; ?>" /></td>
  81.   </tr>
  82.   <tr>
  83.     <td>Marca</td>
  84.     <td><input name="MARCA" type="text" value="<?php echo $row_Recordset1['MARCA']; ?>" /></td>
  85.     <td>Cod/12Nc</td>
  86.     <td><input name="NUM_PRODUCTO" type="text" value="<?php echo $row_Recordset1['NUM_PRODUCTO']; ?>" /></td>
  87.     <td>Revisión</td>
  88.     <td><input name="REVISION" type="text" /></td>
  89.   </tr>
  90.   <input type="hidden" name="MM_update" value="form3">
  91.   <input type="hidden" name="NUM_APARATO" value="<?php echo $row_Recordset1['NUM_APARATO']; ?>">
  92.   <input type="hidden" name="NUM_USUARIO" value="<?php echo $row_Recordset1['NUM_USUARIO']; ?>">
  93.   </table>
  94.   </form>
  95. <?php
  96. mysql_free_result($Recordset1);
  97. ?>

Código Javascript:
Ver original
  1. $updateGoTo = "menu3.php?id=$NUM_USUARIO"; ///Lo estoy haciendo así pero sigue sin funcionar////

Código Javascript:
Ver original
  1. <input type="hidden" name="NUM_USUARIO" value="<?php echo $row_Recordset1['NUM_USUARIO']; ?>">

Gracias.
  #4 (permalink)  
Antiguo 29/11/2012, 11:24
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 9 meses
Puntos: 194
Respuesta: Pasar variable después hacer un update.

en menu3.php puedes recoger la variable con get

Código html:
Ver original
  1. <input type="hidden" name="NUM_USUARIO" value="<?php echo $_GET['NUM_USUARIO']; ?>">
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #5 (permalink)  
Antiguo 29/11/2012, 11:55
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: Pasar variable después hacer un update.

Cita:
Iniciado por h2swider Ver Mensaje
en menu3.php puedes recoger la variable con get

Código html:
Ver original
  1. <input type="hidden" name="NUM_USUARIO" value="<?php echo $_GET['NUM_USUARIO']; ?>">
Hola, otra vez. En menu3.php tengo esto:

Código PHP:
$NUM_USUARIO=$_GET['id'];
mysql_select_db($database_conexion$conexion);
$query_Recordset1 "SELECT * FROM usuarios where NUM_USUARIO like '$NUM_USUARIO'";
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1); 
Que parece estar bien, el problema lo tengo en mandarla:

Código PHP:
$updateGoTo "menu3.php?id=$NUM_USUARIO";
  
header("Location:$updateGoTo");
  exit; 
Código PHP:
<input type="hidden" name="NUM_USUARIO" value="<?php echo $row_Recordset1['NUM_USUARIO']; ?>">
  #6 (permalink)  
Antiguo 29/11/2012, 12:31
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 9 meses
Puntos: 194
Respuesta: Pasar variable después hacer un update.

intenta hacer un echo antes del header location para ver si $updateGoTo tiene lo que realmente quieres

Código PHP:
Ver original
  1. $updateGoTo = "menu3.php?id=$NUM_USUARIO";
  2. echo $updateGoTo ; exit;
  3.   header("Location:$updateGoTo");
  4.   exit;
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #7 (permalink)  
Antiguo 29/11/2012, 12:43
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: Pasar variable después hacer un update.

Una pregunta, esto:

Código:
$updateGoTo = "menu3.php?id=$NUM_USUARIO"; 
  header("Location:$updateGoTo"); 
  exit;
Como se pasa por GET o por POST ?.
  #8 (permalink)  
Antiguo 29/11/2012, 12:58
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 9 meses
Puntos: 194
Respuesta: Pasar variable después hacer un update.

Por get se esta pasando
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #9 (permalink)  
Antiguo 29/11/2012, 13:00
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: Pasar variable después hacer un update.

Cita:
Iniciado por h2swider Ver Mensaje
Por get se esta pasando
Entonces donde está el problema?
  #10 (permalink)  
Antiguo 29/11/2012, 15:42
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: Pasar variable después hacer un update.

OK, era con POST:

Código:
$updateGoTo = "menu3.php?id=" . $_POST["NUM_USUARIO"];
Pero por qué si la recojo con GET :

Código:
$NUM_USUARIO=$_GET['id']; 
mysql_select_db($database_conexion, $conexion); 
$query_Recordset1 = "SELECT * FROM usuarios where NUM_USUARIO like '$NUM_USUARIO'"; 
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
Un saludo.

Etiquetas: formulario, html, mysql, sql, variables, 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 08:17.