PHP Data migration question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • OneSolution

    PHP Data migration question

    Hi All,

    I found out that I can use the header function to redirect a page. However,
    it gives me an error like that:

    Warning: Cannot add header information - headers already sent by (output
    started at /xxx/xxx/html/xx.php:10) in /xxx/xxx/html/xx.php on line 11

    Here's my code:

    <?php

    $name=$_POST["name"];
    $email=$_POST["email"];
    $phone=$_POST["phone"];
    $xxxx=$_POST["xxxx"];
    $currentUserId= $_POST["userid"];

    if (($name != "") && ($email != "") && ($phone != "") && ($xxxx!= "")) {
    echo "processed $userid";
    Header("Locatio n: http://localhost/xxxx/xxxx.asp?id=" . $currentUserId) ;
    }
    ?>

    What I want to do is migrate some data. So my source data is in an MS
    access file, and I've found that I can't simply export the data. So I
    created a form in ASP that will pull each row from the access db into a
    form. The form will auto submit to a PHP. The php will take the submitted
    info and save it to the mysql db. Then it will return the user to the
    original ASP with the userid that was just processed. The ASP will update
    the Access database to show that the row has been saved, and then load the
    next row and continue the process.

    In ASP, I could say

    response.redire ct(http://localhost/location.asp?userid=xxx)

    When I try this in PHP, it complains with the above error message.

    Can anyone help?

    Thanks,
    Z


  • Chris Hope

    #2
    Re: PHP Data migration question

    OneSolution wrote:
    [color=blue]
    > I found out that I can use the header function to redirect a page.
    > However, it gives me an error like that:
    >
    > Warning: Cannot add header information - headers already sent by (output
    > started at /xxx/xxx/html/xx.php:10) in /xxx/xxx/html/xx.php on line 11[/color]

    It's because you have written out some info (echo "processed $userid";)
    which forms the HTML part of the response, before issuing the redirection.
    You cannot do both. Remove or comment out the echo line before the redirect
    and it will remove the error message.

    If you look at the error you received it actually tells you what the problem
    is - "output start at /xxx/xxx/html/xx.php:10" The "10" in this instance is
    telling you the line number that output started. This also happens to be
    the line number your echo statement is on.

    --
    Chris Hope
    The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • OneSolution

      #3
      Re: PHP Data migration question

      Thanks!!!

      I read the error message just fine, but couldn't quite see why it
      complained.

      But then why does the echo statement complain only in some cases while
      working fine in others? This script worked fine for many records, and then
      failed and wouldn't budge. Then I removed the echo statement and it works
      fine.




      "Chris Hope" <chris@electric toolbox.com> wrote in message
      news:1084918973 _925@news.athen anews.com...[color=blue]
      > OneSolution wrote:
      >[color=green]
      > > I found out that I can use the header function to redirect a page.
      > > However, it gives me an error like that:
      > >
      > > Warning: Cannot add header information - headers already sent by (output
      > > started at /xxx/xxx/html/xx.php:10) in /xxx/xxx/html/xx.php on line 11[/color]
      >
      > It's because you have written out some info (echo "processed $userid";)
      > which forms the HTML part of the response, before issuing the redirection.
      > You cannot do both. Remove or comment out the echo line before the[/color]
      redirect[color=blue]
      > and it will remove the error message.
      >
      > If you look at the error you received it actually tells you what the[/color]
      problem[color=blue]
      > is - "output start at /xxx/xxx/html/xx.php:10" The "10" in this instance[/color]
      is[color=blue]
      > telling you the line number that output started. This also happens to be
      > the line number your echo statement is on.
      >
      > --
      > Chris Hope
      > The Electric Toolbox - http://www.electrictoolbox.com/
      >[/color]


      Comment

      Working...