Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts

    header errors on one page but not another

    This is really throwing me for a loop. Here is the code for deleting multiple records from a checkbox. After a successful delete I just want to refresh the page so the header is just pointing to the same page.

    PHP Code:
    <?php
    // Check if bizCat delete button active, start this 
    if(isset($_POST['delete']))     {
    $ids implode(', '$_POST['checkbox']);
    $sql "DELETE FROM userBizCats WHERE id IN($ids)";
    $result mysql_query($sql);

    if(
    $result){
        
    $pgID $row_pageRS['id'];
    header("location: editUsers.php?recordID=$pgID");
    exit;
    }
    }
    ?>
    This same code is in two pages. On one page I get the expected behavior. On the other page I'm thrown this error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/12/9413312/html/admin/editPvtPage.php:277) in /home/content/12/9413312/html/admin/editPvtPage.php on line 286

    There is nearly identical code above this problematic page. No other calls are made to header('location.....

    I'm confused. Any ideas???
    Is there a better way to do this?

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    See the link in my signature about this. It's a common error. Basically your script has output something - html, a blank space, hidden character before your call to header().

    Click my link, take a look and then re-examine the affected script. I bet you have a bit of whitespace there somewhere.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    rgEffects (12-27-2012)

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    I went through your article and went through your explanation. Also went through my problematic page and can't find any white space anywhere.

    Is there another way to refresh a page? I'd like to get rid of using headers if this problem crops up.

    I've got 15 pages now that are using the same solution. Only one is throwing the error.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    output started at /home/content/12/9413312/html/admin/editPvtPage.php:277

    What is on that line?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    The only thing on 277 is <?php

    I carefully went through all of the previous lines of code and removed all of the opening and closing php tags until I got to the validate user and session section on line 44. The entire problem went away then. Funny thing is that in the validate user section at the head of my document is exactly the same on all the restricted pages. This is the only page where that section causes this error.

    Now everything is working fine.

    So here's a general question then. I usually separate different operations by opening and closing php tags when I'm above the HTML because it makes the sections easier to find. I also will put common pieces of code in an include. For example, the code I use to generate menu's is in two sections. The last php call I make before the HTML looks like this:

    PHP Code:
    <?php include('../includes/commonMenuRS.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    .... then farther down the page
    PHP Code:
    <div id="menu">
    <?php include('../includes/commonNavMenu.php'); ?>
    </div>
    Is this a good practice? It certainly makes editing the site easier.
    Last edited by rgEffects; 12-27-2012 at 01:19 PM.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Right, post the entire code for that file please. You're missing something somewhere.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    rgEffects (12-27-2012)

  • #7
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    I found it. There was an empty set of brackets { } in the code up about 20 lines. There were duplicates from a previous if query that had been eliminated and the opening { and closing } brackets were separated by about 20 lines of code. Once I removed the brackets the errors went away.

    Thanks for your help. Wish there was still a way to mark this resolved. It seems that possibility goes away after only a couple of days.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •