PHP - Cannot modify header information - header

 
Vista:

Cannot modify header information - header

Publicado por sandra (60 intervenciones) el 26/06/2007 13:13:46
Hola al actualiar registros me sale este error en pantalla:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/josemaria/gestoractualizar.php:62) in /var/www/josemaria/gestoractualizar.php on line 656

MI CODIGO ES ESTE:

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form1")) {
$updateSQL = sprintf("UPDATE flores SET `ref`=%s, `desc`=%s, precio=%s, disp=%s, exist=%s, foto=%s WHERE num=%s",
GetSQLValueString($_POST['ref'], "text"),
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['precio'], "double"),
GetSQLValueString($_POST['disp'], "text"),
GetSQLValueString($_POST['exist'], "int"),
GetSQLValueString($_POST['foto'], "text"),
GetSQLValueString($_POST['num'], "int"));

mysql_select_db($database_conexionjosemaria, $conexionjosemaria);
$Result1 = mysql_query($updateSQL, $conexionjosemaria) or die(mysql_error());

$updateGoTo = "./muestraoferta.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO flores (`ref`, `desc`, precio, disp, exist, foto) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ref'], "text"),
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['precio'], "double"),
GetSQLValueString($_POST['disp'], "text"),
GetSQLValueString($_POST['exist'], "double"),
GetSQLValueString($_POST['foto'], "text"));

//tomo el valor de un elemento de tipo texto del formulario
$foto = $_POST["foto"];
echo "Referencia: " . $foto . "<br><br>";
//datos del arhivo
$nombre_archivo = $HTTP_POST_FILES['userfile']['name'];
$tipo_archivo = $HTTP_POST_FILES['userfile']['type'];
$tamano_archivo = $HTTP_POST_FILES['userfile']['size'];
//compruebo si las características del archivo son las que deseo
if (!((strpos($tipo_archivo, "gif") || strpos($tipo_archivo, "jpeg")) && ($tamano_archivo < 2000000))) {
echo "La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif o .jpg<br><li>se permiten archivos de 100 Kb máximo.</td></tr></table>";
}else{
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], "/var/www/upload/$nombre_archivo")){
echo "El archivo ha sido cargado correctamente.";
}else{
echo "Ocurrió algún error al subir el fichero. No pudo guardarse.";
}
}


mysql_select_db($database_conexionjosemaria, $conexionjosemaria);
$Result1 = mysql_query($insertSQL, $conexionjosemaria) or die(mysql_error());
}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Cannot modify header information - header

Publicado por Jaterli (1 intervención) el 26/06/2007 14:01:33
Buenas!! el error que te aparece biene de la función header(). Esta funcion modifica las cabeceras del documento html antes de ser enviadas. Por tanto el problema viene de que tu código imprime algún texto antes de modificiar estas cabeceras mediante header() y tu servidor interpreta que se estan enviando 2 veces las cabeceras.

Para ver donde está el error puedes comentar la linea donde pones header(sprintf("Location: %s", $updateGoTo)); y haces un echo "aqui viene el header"; y revisar que texto se está imprimiendo antes de esto y eliminarlo o encerrarlo en un if para que no se ejecute cuando hagas un header posterior.

Saludos!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Cannot modify header information - header

Publicado por sandra (60 intervenciones) el 27/06/2007 11:17:27
Te entiendo, pero donde pongo header(sprintf("Location: %s", $updateGoTo)); ????????

lo ponga donde lo ponga me sale error en la linea donde lo ponga.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Cannot modify header information - header

Publicado por Jaterli (1 intervención) el 27/06/2007 17:20:21
es q es un poquito complicado ver el error sin poder hacer pruebas. Has hecho lo que te dije de comentar la linea del header() y poner un echo "texto"; para ver si delante de "texto" se imprime algo más???
si aun haciendo esto ves que en la página aparece "texto" al principio, ve a ver el código fuente xq puede que ahí veas algunas etiquetas de html que son los que producirian el error.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar