Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-18
6
Medium Priority
?
172 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 111

Accepted Solution

by:
Ray Paseur earned 1600 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

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 111

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.
Suggested Courses

610 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