Foros del Web » Programando para Internet » PHP »

Error al hacer el header solo en el servidor.

Estas en el tema de Error al hacer el header solo en el servidor. en el foro de PHP en Foros del Web. Buenas tardes, me da el siguiente error al realizar un header que en el servidor local me funciona bien y cuando lo subo al servidor ...
  #1 (permalink)  
Antiguo 30/11/2012, 13:17
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Error al hacer el header solo en el servidor.

Buenas tardes, me da el siguiente error al realizar un header que en el servidor local me funciona bien y cuando lo subo al servidor me lo da:

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");

Código:
  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;
Gracias y un saludo
  #2 (permalink)  
Antiguo 30/11/2012, 13:25
Avatar de llorcasantana  
Fecha de Ingreso: octubre-2012
Mensajes: 45
Antigüedad: 11 años, 4 meses
Puntos: 2
Respuesta: Error al hacer el header solo en el servidor.

que es $_POST["NUM_USUARIO"]
__________________
Si crees que estuvo bueno el post, no crees que mereceria un poco de karma?
  #3 (permalink)  
Antiguo 30/11/2012, 13:40
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por llorcasantana Ver Mensaje
que es $_POST["NUM_USUARIO"]
Hola, es una variable que paso a menu3.php
Un saludo
  #4 (permalink)  
Antiguo 30/11/2012, 13:53
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 18 años, 11 meses
Puntos: 839
Respuesta: Error al hacer el header solo en el servidor.

Revisa esto:
http://www.forosdelweb.com/wiki/PHP:...n_line_4%22%3F
Es posible que se esté generando una advertencia en el archivo de conexión que inicia la salida al navegador.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 30/11/2012, 14:30
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por David Ver Mensaje
Revisa esto:
http://www.forosdelweb.com/wiki/PHP:...n_line_4%22%3F
Es posible que se esté generando una advertencia en el archivo de conexión que inicia la salida al navegador.
Gracias por contestar, pero no veo donde está el problema.
  #6 (permalink)  
Antiguo 30/11/2012, 14:39
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Pongo todo el cod:

Código PHP:
<?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=" $_POST["NUM_USUARIO"];
  
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);
?>
  #7 (permalink)  
Antiguo 30/11/2012, 17:21
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Por favor, alguna idea?
  #8 (permalink)  
Antiguo 30/11/2012, 17:55
Avatar de abimex
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: ~
Mensajes: 751
Antigüedad: 17 años
Puntos: 137
Respuesta: Error al hacer el header solo en el servidor.

para que abres y cierras y abres?
Código PHP:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
Ponlo asi
Código PHP:
Ver original
  1. <?php
  2. require_once('Connections/conexion.php');
  3. if (!function_exists("GetSQLValueString")) {
  4. // demas codigo
  #9 (permalink)  
Antiguo 30/11/2012, 18:04
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por abimex Ver Mensaje
para que abres y cierras y abres?
Código PHP:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
Ponlo asi
Código PHP:
Ver original
  1. <?php
  2. require_once('Connections/conexion.php');
  3. if (!function_exists("GetSQLValueString")) {
  4. // demas codigo
Gracias por responder pero sigue igual:

Código PHP:
<?php 
require_once('Connections/conexion.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=" $_POST["NUM_USUARIO"];
  
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);
?>
  #10 (permalink)  
Antiguo 30/11/2012, 18:07
Avatar de kreil  
Fecha de Ingreso: septiembre-2012
Ubicación: España
Mensajes: 63
Antigüedad: 11 años, 6 meses
Puntos: 16
Respuesta: Error al hacer el header solo en el servidor.

Hola! El problema es que estás mandando algún dato previamente.
Cuando haces un header, no debes hacer ninguna impresión por pantalla previamente, es decir, no pongas ningún print o echo antes del header.

EDITO: según el error, estás mandando algún dato en la linea 2 de conexion.php
__________________
Diseñador y programador de El break; de la informática
  #11 (permalink)  
Antiguo 30/11/2012, 18:11
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Ya, pero es que tengo pocos conocimientos de php y no veo donde está el error.
Gracias
  #12 (permalink)  
Antiguo 30/11/2012, 18:11
Avatar de abimex
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: ~
Mensajes: 751
Antigüedad: 17 años
Puntos: 137
Respuesta: Error al hacer el header solo en el servidor.

pon el codigo de conexion.php
  #13 (permalink)  
Antiguo 30/11/2012, 18:15
Avatar de kreil  
Fecha de Ingreso: septiembre-2012
Ubicación: España
Mensajes: 63
Antigüedad: 11 años, 6 meses
Puntos: 16
Respuesta: Error al hacer el header solo en el servidor.

Y por cierto, también tienes que tener en cuenta que session_start() se debe poner una sola vez en todo el código que se esté generando en esa página concreta.
Si tienes varios includes y en cada uno de ellos pones session_start() te lanzará error.
También te lanza error si escribes HTML antes del session_start().

Checkea todo eso y cuéntanos!
__________________
Diseñador y programador de El break; de la informática
  #14 (permalink)  
Antiguo 30/11/2012, 18:18
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por abimex Ver Mensaje
pon el codigo de conexion.php
conexion.php

Código PHP:
<?php
$hostname_conexion 
"localhost:3306";
$database_conexion "pruebas";
$username_conexion "xxxxx";
$password_conexion "xxxxxxx";
$conexion mysql_pconnect($hostname_conexion$username_conexion$password_conexion) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
Gracias
  #15 (permalink)  
Antiguo 30/11/2012, 18:22
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por kreil Ver Mensaje
Y por cierto, también tienes que tener en cuenta que session_start() se debe poner una sola vez en todo el código que se esté generando en esa página concreta.
Si tienes varios includes y en cada uno de ellos pones session_start() te lanzará error.
También te lanza error si escribes HTML antes del session_start().

Checkea todo eso y cuéntanos!
No tengo nada de eso, y por qué me funciona bien en el servidor localhost?
  #16 (permalink)  
Antiguo 30/11/2012, 18:37
Avatar de kreil  
Fecha de Ingreso: septiembre-2012
Ubicación: España
Mensajes: 63
Antigüedad: 11 años, 6 meses
Puntos: 16
Respuesta: Error al hacer el header solo en el servidor.

La verdad es que está dificil esto... xD

Realmente no se porqué puede pasar, pero a mi también me ha pasado en numerosas ocasiones.
De todas formas ese error no va a parar tu página por lo que si desactivas la impresión de errores en el servidor todo debería funcionar correctamente.

Otra posible solución, aunque nunca la he probado, es cambiar la codificación del archivo a ANSI con el bloc de notas... Lo he leído por ahí en internet, no se si resultará.
__________________
Diseñador y programador de El break; de la informática
  #17 (permalink)  
Antiguo 30/11/2012, 18:37
Avatar de abimex
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: ~
Mensajes: 751
Antigüedad: 17 años
Puntos: 137
Respuesta: Error al hacer el header solo en el servidor.

antes del header, pon die; si te imprime algún error, eso es lo que esta enviando las cabezeras,
  #18 (permalink)  
Antiguo 30/11/2012, 18:46
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por abimex Ver Mensaje
antes del header, pon die; si te imprime algún error, eso es lo que esta enviando las cabezeras,
Ya no me sale el error, se me queda la pagina en blanco. He puesto esto:

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

Hay otra forma de redirigirla a menu3.php porque la actualización si que me la hace?
Gracias
  #19 (permalink)  
Antiguo 30/11/2012, 18:48
Avatar de abimex
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: ~
Mensajes: 751
Antigüedad: 17 años
Puntos: 137
Respuesta: Error al hacer el header solo en el servidor.

es que ha de haber algun espacio en blanco, revisa bien tu codigo, intentalo bien para que veas donde es
  #20 (permalink)  
Antiguo 30/11/2012, 18:54
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 6 meses
Puntos: 10
Respuesta: Error al hacer el header solo en el servidor.

Cita:
Iniciado por abimex Ver Mensaje
es que ha de haber algun espacio en blanco, revisa bien tu codigo, intentalo bien para que veas donde es
Pero tiene que ser en este código o puede ser tambien en los demas donde hago las llamadas?
Y perdona pero de debe de haber otra forma de hacer un update y recuperar esos datos no?

Última edición por satjaen; 30/11/2012 a las 19:05

Etiquetas: header, mysql, 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 18:11.