470,874 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

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("Location: 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.redirect(http://localhost/location.asp?userid=xxx)

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

Can anyone help?

Thanks,
Z
Jul 17 '05 #1
2 1664
OneSolution wrote:
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


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/
Jul 17 '05 #2
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" <ch***@electrictoolbox.com> wrote in message
news:10************@news.athenanews.com...
OneSolution wrote:
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
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/

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Keith R | last post: by
6 posts views Thread by Dave | last post: by
1 post views Thread by pankaj_wolfhunter | last post: by
2 posts views Thread by contact1981 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.