Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-24-2012, 10:06 PM   PM User | #1
rgEffects
New Coder

 
Join Date: Aug 2012
Posts: 76
Thanks: 22
Thanked 0 Times in 0 Posts
rgEffects is an unknown quantity at this point
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?
rgEffects is offline   Reply With Quote
Old 12-24-2012, 10:20 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Users who have thanked tangoforce for this post:
rgEffects (12-27-2012)
Old 12-27-2012, 12:40 AM   PM User | #3
rgEffects
New Coder

 
Join Date: Aug 2012
Posts: 76
Thanks: 22
Thanked 0 Times in 0 Posts
rgEffects is an unknown quantity at this point
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.
rgEffects is offline   Reply With Quote
Old 12-27-2012, 01:05 AM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
output started at /home/content/12/9413312/html/admin/editPvtPage.php:277

What is on that line?
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Old 12-27-2012, 12:40 PM   PM User | #5
rgEffects
New Coder

 
Join Date: Aug 2012
Posts: 76
Thanks: 22
Thanked 0 Times in 0 Posts
rgEffects is an unknown quantity at this point
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..
rgEffects is offline   Reply With Quote
Old 12-27-2012, 12:42 PM   PM User | #6
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Right, post the entire code for that file please. You're missing something somewhere.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Users who have thanked tangoforce for this post:
rgEffects (12-27-2012)
Old 12-27-2012, 10:36 PM   PM User | #7
rgEffects
New Coder

 
Join Date: Aug 2012
Posts: 76
Thanks: 22
Thanked 0 Times in 0 Posts
rgEffects is an unknown quantity at this point
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.
rgEffects is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:14 AM.


Advertisement
Log in to turn off these ads.