-3

Possible Duplicate:
Reference - What does this error mean in PHP?

I have problem in Header function. I want to redirect the page to the paypal after the insertion in database. Insertion query is working correctly pay header function is not working.

Here is my code

{
mysql_query("INSERT INTO bookings (date,time,hired_consultant,status,user_id) VALUES ('$date','$time','$hired_consultant','pending','$user_id')",$link)or die("Invalid: " . mysql_error());
header("Location: https://www.paypal.com/cgi-bin/webscr");
exit();
}

After insert following error appears:

Warning: Cannot modify header information - headers already sent by (output started at /home/nausalho/public_html/HumanResource/selection1.php:2) in /home/nausalho/public_html/HumanResource/selection1.php on line 101

Its is working fine on my localhost. But on live site it didnot redirect me to the paypal, just appear error message on the same page.

Please figure out my mistake in code or any other redirect method. Thanks in advance,

Community
  • 1
  • 1
Sam
  • 243
  • 2
  • 5
  • 18
  • 3
    Please post your full script, it looks like there is an empty line before your – Gregor Jan 18 '13 at 08:24
  • 1
    Make sure you saved the php file without BOM if it is saved as UTF8 file. – Thomas Kekeisen Jan 18 '13 at 08:24
  • 1
    Re "Please figure out my mistake": SO is not the place to come and ask people to do your debugging, especially when Headers already sent has been asked and answered a hundred times before. Please use the search function before asking questions. We expect you to do that. – Gordon Jan 18 '13 at 08:25
  • 3
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://stackoverflow.com/a/14110189/1723893). – NullPoiиteя Jan 18 '13 at 08:26

2 Answers2

0

Add this to the top of your page:

ini_set('output_buffering', 'on');
-3

Use the below code echo "window.location.href = 'https://www.paypal.com/cgi-bin/webscr'";die;

Vinod Kumar
  • 1,479
  • 3
  • 13
  • 23
  • Redirection using PHP not javascript, just see the whats wrong in the header function – Afsar Jan 18 '13 at 08:30
  • Headers must be parsed before any HTML, and for some reason (Unknown by me, but I'm sure others can answer why) certain hosts don't like it when you place any HTML above header tags. – Vinod Kumar Jan 18 '13 at 08:32