Solved

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

Posted on 2013-01-18
6
166 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
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 108

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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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 108

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now