Solved

Headers already sent issue, Can i just remove the goto lines of code?

Posted on 2013-01-18
6
170 Views
Last Modified: 2013-01-21
I have a form that is deleting a user.  It works fine, but gives me the "Headers already sent" error on the page.  I'd like to not have that show up and get this to work correctly.

I have attached the snippet that I am using after the "DELETE" from DB code.

Open in new window

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "infoID")) {
if ((isset($_GET['userID'])) && ($_GET['userID'] != "")) {
  $deleteSQL = sprintf("DELETE FROM tblusers WHERE userID=%s",
                       GetSQLValueString($_GET['userID'], "int"));

  mysql_select_db($database_con_db_local, $con_db_local);
  $Result1 = mysql_query($deleteSQL, $con_db_local) or die(mysql_error());

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

Open in new window

0
Comment
Question by:axessJosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38793584
There must be absolutely nothing sent to the browser before the header function, even a blank line before the <?php tag will cause the error you cannot echo or do anything else that sends something to the browser before the header.

Cd&
0
 
LVL 2

Author Comment

by:axessJosh
ID: 38793593
the file that is being used to process the deletion is inserted using:

<?php include_once (); ?>

since the file its included in is also PHP, could there be a conflict of some kind there?
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 400 total points
ID: 38793670
Yes, there could be a conflict there.  There is probably a newline character of invisible whitespace.  You can add ob_start() as the first PHP statement in the first script and it will probably solve the problem.  It may make your scripts run faster, too!
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38795941
Extra php brackets cause white space to be added in between them.  The newlines that Ray mentioned are in between the ?> at the end of the first line and <?php on the second line.

<?php include_once (); ?>
<?php include_once (); ?>

Open in new window

0
 
LVL 11

Expert Comment

by:mcnute
ID: 38796232
ob_start();

Open in new window

is your friend as Ray pointed out.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38802414
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question