Pure PHP Upload Add-On Pack Support Product Page

Update and Delete before Update running into header issues on redirect

Asked 14 Sep 2010 03:34:43
1
has this question
14 Sep 2010 03:34:43 Julia Minnie posted:
Works fine on my testing server locally, but live, when I submit a form to update a table that includes a possible new document upload, the redirect does not work, though the update itself does appear to be working.


Warning: Cannot modify header information - headers already sent by (output started at /home/minersma/public_html/admin/properties_edit.php:5) in /home/minersma/public_html/admin/properties_edit.php on line 111(line 111 is line 71 here)

I presume it's a case of order of operations, but I have no idea where to look. Can anyone help? Page code below.

Cheers,
Julia


<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>

<?php

// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../properties";
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "3000";
$ppu->nameConflict = "over";
$ppu->requireUpload = "false";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "showProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

if (!function_exists("GetSQLValueString")) {...}

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

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
		}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}
// FORM VALIDATION {...}

if (!$error) {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
	//check to see if a new property description is being uploaded, else, keep the original
	if (empty($_POST['property_details'])) {
		$_POST['property_details'] = $_POST['property_detailsAlt'];
	}
  $updateSQL = sprintf("UPDATE tbl_properties SET property_title=%s, property_location=%s, property_contactname=%s, property_contactemail=%s, property_contactphone=%s, property_desc=%s, property_details=%s, property_display=%s WHERE property_ID=%s",
                       GetSQLValueString($_POST['property_title'], "text"),
                       GetSQLValueString($_POST['property_location'], "text"),
                       GetSQLValueString($_POST['property_contactname'], "text"),
                       GetSQLValueString($_POST['property_contactemail'], "text"),
                       GetSQLValueString($_POST['property_contactphone'], "text"),
                       GetSQLValueString($_POST['property_desc'], "text"),
                       GetSQLValueString($_POST['property_details'], "text"),
                       GetSQLValueString(isset($_POST['property_display']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['property_ID'], "int"));

  mysql_select_db($database_dbconnect, $dbconnect);
  $Result1 = mysql_query($updateSQL, $dbconnect) or die(mysql_error());

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


Replies

Replied 14 Sep 2010 15:57:21
14 Sep 2010 15:57:21 Miroslav Zografski replied:
Hello Julia,

It seems that the form validation needs to be executed first and the Pure Upload needs to be in the same If statement block as the update behavior.

Try that way and get back to me with a feedback.

Regards,
Replied 14 Sep 2010 23:54:37
14 Sep 2010 23:54:37 Julia Minnie replied:
Thanks for the suggestion Miroslav,
Unfortunately, I don't seem to be making progress. I wasn't sure exactly which bit of code for PureUpload needed to be in the if block, but I tried a number of formations with the same results. Here's my latest version.

I tried using the redirect in PureUpload and turned off the redirect in the upload behaviour, but no luck. I cannot see where header info is being sent for the 'second' time that causes the warning.

<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>

<?php

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

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
	}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}

// FORM VALIDATION
$error = array();
$MM_flag="MM_update";
if (isset($_POST[$MM_flag])) {
 if (empty($_POST['property_title'])) {
	 $error['title'] = "A title is required";
 }
 }
 
if (!$error) {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
	//check to see if a new property description is being uploaded, else, keep the original
	if (empty($_POST['property_details'])) {
		$_POST['property_details'] = $_POST['property_detailsAlt'];
	}
	
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../properties";
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "3000";
$ppu->nameConflict = "over";
$ppu->requireUpload = "false";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "showProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "properties_admin.php";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

  $updateSQL = sprintf("UPDATE tbl_properties SET property_title=%s, property_location=%s, property_contactname=%s, property_contactemail=%s, property_contactphone=%s, property_desc=%s, property_details=%s, property_display=%s WHERE property_ID=%s",
                       GetSQLValueString($_POST['property_title'], "text"),
                       GetSQLValueString($_POST['property_location'], "text"),
                       GetSQLValueString($_POST['property_contactname'], "text"),
                       GetSQLValueString($_POST['property_contactemail'], "text"),
                       GetSQLValueString($_POST['property_contactphone'], "text"),
                       GetSQLValueString($_POST['property_desc'], "text"),
                       GetSQLValueString($_POST['property_details'], "text"),
                       GetSQLValueString(isset($_POST['property_display']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['property_ID'], "int"));

  mysql_select_db($database_dbconnect, $dbconnect);
  $Result1 = mysql_query($updateSQL, $dbconnect) or die(mysql_error());

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

$colname_getProperty = "-1";
if (isset($_GET['id'])) {
  $colname_getProperty = $_GET['id'];
}
mysql_select_db($database_dbconnect, $dbconnect);
$query_getProperty = sprintf("SELECT * FROM tbl_properties WHERE property_ID = %s", GetSQLValueString($colname_getProperty, "int"));
$getProperty = mysql_query($query_getProperty, $dbconnect) or die(mysql_error());
$row_getProperty = mysql_fetch_assoc($getProperty);
$totalRows_getProperty = mysql_num_rows($getProperty);
?>
Replied 15 Sep 2010 09:31:11
15 Sep 2010 09:31:11 Miroslav Zografski replied:
Hello Julia,

Here try out this :

<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
// FORM VALIDATION
$error = array();
$MM_flag="MM_update";
if (isset($_POST[$MM_flag])) {
 if (empty($_POST['property_title'])) {
	 $error['title'] = "A title is required";
 }
}
if (!$error) {
?>
	
<?
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../properties";
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "3000";
$ppu->nameConflict = "over";
$ppu->requireUpload = "false";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "showProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "properties_admin.php";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
	}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
	//check to see if a new property description is being uploaded, else, keep the original
	if (empty($_POST['property_details'])) {
		$_POST['property_details'] = $_POST['property_detailsAlt'];
	}

  $updateSQL = sprintf("UPDATE tbl_properties SET property_title=%s, property_location=%s, property_contactname=%s, property_contactemail=%s, property_contactphone=%s, property_desc=%s, property_details=%s, property_display=%s WHERE property_ID=%s",
                       GetSQLValueString($_POST['property_title'], "text"),
                       GetSQLValueString($_POST['property_location'], "text"),
                       GetSQLValueString($_POST['property_contactname'], "text"),
                       GetSQLValueString($_POST['property_contactemail'], "text"),
                       GetSQLValueString($_POST['property_contactphone'], "text"),
                       GetSQLValueString($_POST['property_desc'], "text"),
                       GetSQLValueString($_POST['property_details'], "text"),
                       GetSQLValueString(isset($_POST['property_display']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['property_ID'], "int"));

  mysql_select_db($database_dbconnect, $dbconnect);
  $Result1 = mysql_query($updateSQL, $dbconnect) or die(mysql_error());

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

$colname_getProperty = "-1";
if (isset($_GET['id'])) {
  $colname_getProperty = $_GET['id'];
}
mysql_select_db($database_dbconnect, $dbconnect);
$query_getProperty = sprintf("SELECT * FROM tbl_properties WHERE property_ID = %s", GetSQLValueString($colname_getProperty, "int"));
$getProperty = mysql_query($query_getProperty, $dbconnect) or die(mysql_error());
$row_getProperty = mysql_fetch_assoc($getProperty);
$totalRows_getProperty = mysql_num_rows($getProperty);
?>
Replied 15 Sep 2010 21:41:53
15 Sep 2010 21:41:53 Julia Minnie replied:
Rats! Same problem. It works quietly on my local setup, but remotely it now it throws two warnings, because I've got the redirect defined in both PureUpload and the Update Behaviour.

Note--the actual update and uploads are working, it's just the redirects that are failing.

Any thoughts on what might be calling the later header?

Warning: Cannot modify header information - headers already sent by (output started at /home/minersma/public_html/admin/properties_edit.php:5) in /home/minersma/public_html/ScriptLibrary/incPureUpload.php on line 377

Warning: Cannot modify header information - headers already sent by (output started at /home/minersma/public_html/admin/properties_edit.php:5) in /home/minersma/public_html/admin/properties_edit.php on line 115


Edited by - Julia Minnie on 15 Sep 2010  21:43:46
Replied 16 Sep 2010 10:23:59
16 Sep 2010 10:23:59 Miroslav Zografski replied:
Hello Julia,

Set redirect only to Update Record.

Regards,
Replied 16 Sep 2010 20:14:58
16 Sep 2010 20:14:58 Julia Minnie replied:
Nope. That is not the problem. I still get a warning:

Warning: Cannot modify header information - headers already sent by (output started at /home/minersma/public_html/admin/properties_edit.php:5) in /home/minersma/public_html/admin/properties_edit.php on line 115

It looks like something is trying to send header info after the redirect has been defined in the Update Behaviour. I can't see what it is, though.

Julia
Replied 17 Sep 2010 09:55:49
17 Sep 2010 09:55:49 Miroslav Zografski replied:
Hello Julia,

Please, provide me the page in question at my e-mail:

Regards,

Reply to this topic