Solved

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

Posted on 2013-01-18
6
168 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 109

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 109

Expert Comment

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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magento: different theme for Pc and for mobile devices 4 31
php help 34 58
How does PHP Storm display on Linux high resolution laptops? 1 36
Combining Queries 7 27
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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