Ir al contenido


Foto

Pasar variable después de hacer un update en php


  • Por favor identifícate para responder
3 respuestas en este tema

#1 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 29 noviembre 2012 - 12:02

Hola compañeros, necesito vuestra ayuda para pasar una variable de un formulario. La variaable es NUM_USUARIO que la tengo en el SELECT y después lo que quiero es mandarla a la pagina menu3.php. Pongo el código es un SELECT Y UN UPDATE y en el interior detallo.


<?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;
}
}

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  $updateSQL = sprintf("UPDATE ap_usuarios SET NUM_USUARIO=%s,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",
                      GetSQLValueString($_POST['NUM_USUARIO'], "text"),
  GetSQLValueString($_POST['MODELO'], "text"),
                      GetSQLValueString($_POST['MARCA'], "text"),
                      GetSQLValueString($_POST['APARATO'], "text"),
                      GetSQLValueString($_POST['COD_APARATO'], "text"),
                      GetSQLValueString($_POST['GRUPO'], "text"),
                      GetSQLValueString($_POST['NUM_PRODUCTO'], "text"),
                      GetSQLValueString($_POST['REVISION'], "text"),
                      GetSQLValueString($_POST['FD'], "text"),
                      GetSQLValueString($_POST['NUM_SERIE'], "text"),
                      GetSQLValueString($_POST['DISTRIBUIDOR'], "text"),
                      GetSQLValueString($_POST['ASEGURADORA'], "text"),
                      GetSQLValueString($_POST['FECHA_COMPRA'], "date"),
                      GetSQLValueString($_POST['INICIO_GARANTIA'], "date"),
                      GetSQLValueString($_POST['FIN_GARANTIA'], "date"),
                      GetSQLValueString($_POST['NUM_APARATO'], "int"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($updateSQL, $conexion) or die(mysql_error());
  $updateGoTo = "menu3.php?id=$NUM_USUARIO"; ///////////////Aquí es donde no me manda la variable////////////////////
  header("Location:$updateGoTo");
  exit;
}
$num_aparato=$_GET['ID'];
mysql_select_db($database_conexion, $conexion);
$query_Recordset1 = "SELECT * FROM ap_usuarios where num_aparato = '$num_aparato'";
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<form method="post" name="form3" action="<?php echo $editFormAction; ?>">
<table width="100%">
  <tr>
    <td>Aparato</td>
    <td><input name="APARATO" type="text" value="<?php echo $row_Recordset1['APARATO']; ?>" /></td>
    <td>Modelo</td>
    <td><input name="MODELO" type="text" value="<?php echo $row_Recordset1['MODELO']; ?>" /></td>
    <td>NºSerie</td>
    <td><input name="NUM_SERIE" type="text" value="<?php echo $row_Recordset1['NUM_SERIE']; ?>" /></td>
  </tr>
  <tr>
    <td>Marca</td>
    <td><input name="MARCA" type="text" value="<?php echo $row_Recordset1['MARCA']; ?>" /></td>
    <td>Cod/12Nc</td>
    <td><input name="NUM_PRODUCTO" type="text" value="<?php echo $row_Recordset1['NUM_PRODUCTO']; ?>" /></td>
    <td>Revisión</td>
    <td><input name="REVISION" type="text" /></td>
  </tr>
  <input type="hidden" name="MM_update" value="form3">
  <input type="hidden" name="NUM_APARATO" value="<?php echo $row_Recordset1['NUM_APARATO']; ?>">
  <input type="hidden" name="NUM_USUARIO" value="<?php echo $row_Recordset1['NUM_USUARIO']; ?>">
  </table>
  </form>
<?php
mysql_free_result($Recordset1);
?>


Gracias y un saludo.
  • 0

#2 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 29 noviembre 2012 - 01:16

Prueba de las siguientes formas:

$updateGoTo = "menu3.php?id=" . $NUM_USUARIO;

// ó

$updateGoTo = "menu3.php?id=" . $_POST["NUM_USUARIO"];

//ó

$updateGoTo = "menu3.php?id=" . $_GET["NUM_USUARIO"];


Con eso te dará la pausa a seguir.

Saludos.
  • 0

#3 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 29 noviembre 2012 - 03:03

Prueba de las siguientes formas:

$updateGoTo = "menu3.php?id=" . $NUM_USUARIO;

// ó

$updateGoTo = "menu3.php?id=" . $_POST["NUM_USUARIO"];

//ó

$updateGoTo = "menu3.php?id=" . $_GET["NUM_USUARIO"];


Con eso te dará la pausa a seguir.

Saludos.


Ok, muchas gracias era $updateGoTo = "menu3.php?id=" . $_POST["NUM_USUARIO"];, pero por qué si yo luego lo recojo en menu3.php con GET :huh::

[html5]
$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);[/html5]

UN SALUDO
  • 0

#4 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 30 noviembre 2012 - 01:13

Tengo un problema  :angry: y es que en el  localhost me funciona bien pero al subirlo al servidor me da error:


Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\xn--electrodiseo-khb.es\httpdocs\Wedserver\Connections\conexion.php :2) in C:\Inetpub\vhosts\xn--electrodiseo-khb.es\httpdocs\Wedserver\actualizar_aparatos.php on line 61

Y en la linea 61 del cod tengo header("Location:$updateGoTo");

cod:

[html5]
  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($updateSQL, $conexion) or die(mysql_error());
  $updateGoTo = "menu3.php?id=" . $_POST["NUM_USUARIO"];
  header("Location:$updateGoTo");
  exit;
[/html5]

Gracias
  • 0




IP.Board spam blocked by CleanTalk.