0

wonder if anyone could help. my problem is that the site works on localhost but when I ftp it to a live server the header() doesn't redirect them to (in this case) a thank you page, the data how ever is recorded in the database.

PHP code:

<?php
    if (isset($_POST['submit'])) {
    $connect_error = 'Sorry, Connection problems.';
    mysql_connect('localhost', 'user', 'password') or die($connect_error);
    mysql_select_db('email_logs') or die($connect_error);

    $sql = "INSERT INTO client_data (name, email) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['email']) . "')";
    mysql_query($sql);
    mysql_close();
    header("Location: thankyou.php");
    exit();
}
?>
user2682649
  • 1
  • 1
  • 3
  • you forgot to upload thankyou.php? Or it's not where you think it is? – Jeroen Ingelbrecht Aug 25 '13 at 09:42
  • Did you get any error instead? – Ahmad Aug 25 '13 at 09:44
  • 2
    Offtopic: don't use mysql_* functions, it's deprecated, use mysqli or PDO instead – M.Svrcek Aug 25 '13 at 09:44
  • The thank you page is uploaded, if I type the url of the website in the bar and include /thankyou.php it shows that thank you page. – user2682649 Aug 25 '13 at 09:49
  • and nope no errors what so ever.. – user2682649 Aug 25 '13 at 09:49
  • Do you get errors in other pages? Maybe displaying errors is disabled in your server. – Ahmad Aug 25 '13 at 09:51
  • What are the versions of PHP (both local and remote)? – putvande Aug 25 '13 at 09:52
  • error messages are enables on the server, and they are running version 5.3. my local server is through xammp, how would I check the php version? sorry a little new to this. – user2682649 Aug 25 '13 at 09:59
  • nevermind, fount it. Im running version 5.4.16 – user2682649 Aug 25 '13 at 10:01
  • Try replacing header() for echo() or something, it's the most primitive form of debugging. Also, if you found solved issue, please close your question and/or answer itself properly! – Leonel Aug 25 '13 at 10:25
  • thanks everyone okay so ive includes the ob_start("ob_gzhandler"); at the top aswell as the error reporting line, and its returned this error "Warning: Cannot modify header information - headers already sent by (output started at /home/kia03/public_html/index.php:2) in /home/kia03/public_html/index.php on line 30" – user2682649 Aug 25 '13 at 10:50
  • [check out this post regarding php headers](http://stackoverflow.com/questions/423860/php-header-redirect-not-working) – Breign Aug 25 '13 at 11:19

4 Answers4

1

your code is fine...if u want u can try defining relative paths like.../path/to/thankyou.php..watch what happens..if it still not running..then check by error_reporting(E_ALL);ini_set('display_errors', 1); and tell us what the actual error

RbG
  • 3,181
  • 3
  • 32
  • 43
1

This may help you.

ob_start();

You can add this at the top of thankyou.php

emmanuel
  • 9,607
  • 10
  • 25
  • 38
0

Try this at the top of the script

ob_start("ob_gzhandler");
Jeff
  • 947
  • 2
  • 9
  • 23
  • read the article and checked for everything that was listed in it, still nothing works... Is there a way to instead of redirecting rather have the form disappear and a thank you message replace it? – user2682649 Aug 25 '13 at 12:05
0

Try with the below piece of code

fileName:fix.php

<?php
ob_start();
...
header('Location: page1.php');
...
ob_end_flush();
?>
IRSHAD
  • 2,855
  • 30
  • 39