Getting header error on production server not in localhost

Discussion in 'PHP' started by webdeveloperindia, Oct 5, 2011.

  1. #1
    Hey Guys tried to find out why I am getting this Error in my Production server. in localhost everything is fine. can anyone please tell me why this happens and what is its solution ?
    [/B][/B][/B]
    [B]Warning: Cannot modify header information - headers already sent by (output started at /home/root/public_html/mysite.com/insert_bill_ie.php:12) in[/B][B]/home/susheel/public_html/[B]mysite.com[/B]/insert_bill_ie.php on line [B]213
    
    Code (markup):

     
    webdeveloperindia, Oct 5, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Post the contents of insert_bill_ie.php
     
    jestep, Oct 5, 2011 IP
  3. webdeveloperindia

    webdeveloperindia Active Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    73
    #3
    Hey jestep Thanks for your reply !!

    Here is the content code
    
    <?php 
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "insertform")) {
      $insertSQL = sprintf("INSERT INTO bill_i_e (type, ms, clearing_chrgs, shippedper, beno, blno,billno, pod, noofqty, bedate, billdate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s)",
                           GetSQLValueString($_POST['type'], "text"),
                           GetSQLValueString($_POST['ms'], "text"),
                           GetSQLValueString($_POST['clearingchrgs'], "text"),
                           GetSQLValueString($_POST['shipedper'], "text"),
                           GetSQLValueString($_POST['beno'], "text"),
                           GetSQLValueString($_POST['blno'], "text"),
    					     GetSQLValueString($_POST['billno'], "text"),
                           GetSQLValueString($_POST['pod'], "text"),
                           GetSQLValueString($_POST['noofqty'], "text"),
                           GetSQLValueString($_POST['bedate'], "date"),
                           GetSQLValueString($_POST['billdate'], "date"));
    $billno=$_POST['billno'];
      mysql_select_db($database_connection, $connection);
      $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
    
      $insertGoTo = "insert_bill_ie.php?billno=$billno";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    
    ?>
    
    
    Code (markup):
     
    webdeveloperindia, Oct 5, 2011 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    seems like there's no line 213 from it, is there any other files that are included?
     
    JohnnySchultz, Oct 6, 2011 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    Very simple solution. At the top of the file, on the lime immediately after <?php, add:

    ob_start();

    (If there's a single character - even a space - after the <?php, other than the newline, it won't work no matter what else you do.

    Since you seem to have one blank line at the top of your code, headers are sent at that point. When the code reaches

    header(sprintf("Location: %s", $insertGoTo));
    it blows up, because you can't send headers after they've been sent. Turning on the output buffer (ob_start() is output_buffer_start) fixes the problem, since nothing gets sent until you flush the buffer or run off the page.
     
    Rukbat, Oct 7, 2011 IP
  6. webdeveloperindia

    webdeveloperindia Active Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    73
    #6
    wow ..! Rukbat is grate.
    You solved my problem
    Thanks !!
     
    webdeveloperindia, Oct 7, 2011 IP