Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:00:45+00:00 2026-05-28T06:00:45+00:00

I have a heredoc form (shown below) inside addToDb.php. The form posts back to

  • 0

I have a heredoc form (shown below) inside addToDb.php. The form posts back to addToDb.php when the user clicks the submit button on the form (the ‘ADD RECORD’ button in the form below).

After verifying that I have okay data on the form, I add the data to my database and use header() to 303 redirect (this is the my 1st attempt ever to use post/redirect/get).

I get an error:

“Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\foo\addToDb.php:165) in C:\xampp\htdocs\foo\addToDb.php on line 129 and in C:\xampp\htdocs\foo\addToDb.php on line 130”

 echo <<<_END
  <h1>Please add a new student....</h1>
  <p>Fields with an asterisk (*) are required fields.</p>
  <form action="addToDb.php" method="post">
    <b><i>First name *</b></i> : <input type="text" name=$firstNameLabel /><br />
 Middle initial  : <input type="text" name=$middleInitialLabel /><br />
     <b><i>Last name *</b></i> : <input type="text" name=$lastNameLabel /><br />
       <b><i>School*</i></b> : <input type="text" name=$schoolLabel size=40/><br />
      Grade: <input type="text" name=$gradeLabel /><br />
         <b><i>Email *</b></i> : <input type="text" name=$emailLabel size=40 /><br />
    <input type="submit" name="addrecord" value="ADD RECORD" /><br />
</form>
_END;

*(NOTE: the _END above, which closes the heredoc, appears on line 165 in addToDb.php — that line 165 is mentioned in the error message I get.)*

So when the ‘ADD RECORD’ submit button is pushed, the same addToDb.php file is re-entered and the same form as above is displayed again.

When addToDb.php is re-entered due to the submit, I check for valid form data supplied by the user and save to the database if it’s valid data and call header() as follows:

// check for valid form data and add to the database, then redirect now.........
header("HTTP/1.1 303 See Other");
header("Location: http://localhost/foo/index.php");
exit();

(NOTE: the two calls to header above appear on lines 129 and 130 in addToDb.php)

So here’s what happens:

  • I fill in the form with valid data
  • push ‘ADD RECORD’
  • then the form is re-displayed as I re-enter addToDb.php
  • my record successfully gets added to the database, but……
  • I do not see index.php in the browser, I still see addToDb.php
  • and I get the error message as described above and repeated below:

“Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\foo\addToDb.php:165) in C:\xampp\htdocs\foo\addToDb.php on line 129 and in C:\xampp\htdocs\foo\addToDb.php on line 130”

I have used the heredoc approach in the past with no problems.

But this is the very first time in my life I am trying to implement Post/Redirect/Get.

So — is the heredoc somehow interfering with my PRG?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:00:46+00:00Added an answer on May 28, 2026 at 6:00 am

    The headers must be the first thing sent to the client. You can do anything you like in the code first (i.e. test the post/get variables) as long as you don’t send any data to the client (i.e. use echo or place plain html outside of php tags) before sending the http headers. After the headers are sent you can, of course, do what ever you like.

    So you are getting the error:

    Cannot modify header information - headers already sent by...
    

    The headers were automatically provided at the beginning of the document, because you didn’t provide yours there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form for that a user fills out and submits. Once submitted
If I have a page with multiple <?php ... ?> sections interspresed with pure
I have 9000 PHP files , most of which contain the text foo .
I have the following PHP code, but it's not working. I don't see any
I have a heredoc where I am using #{} to interpolate some other strings,
A test sample of my xml file is shown below: test.xml <feed> <entry> <title>Link
Have any one tried to activate fancybox thumbnail gallery using a button or an
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine
Im new to php and I have a templating system in which I orignally
I have the following code: <?php if ($zweck == buchhaltung) { echo <<<EOF <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.