0

Warning: Cannot modify header information - headers already sent by (output started at /srv/disk2/1201823/www/-----------.org/Florida/bookingV1.php:1) in /srv/disk2/1201823/www/-----------.org/Florida/bookingV1.php

This is the error I'm getting. How can I fix it?

Here's my code.

<?php

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
    $x = $_POST['NoOfPass'] * 500;
    $insertSQL = sprintf("INSERT INTO booking2 (Lastname, Firstname, Email, Address, ContactNo, BusType, `From`, `To`, NoOfPass, DateMonth, `Day`, `Time`,Amount) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,$x)", 
            GetSQLValueString($_POST['Lastname'], "text"), 
            GetSQLValueString($_POST['Firstname'], "text"), 
            GetSQLValueString($_POST['Email'], "text"), 
            GetSQLValueString($_POST['Address'], "text"), 
            GetSQLValueString($_POST['ContactNo'], "int"), 
            GetSQLValueString($_POST['BusType'], "text"), 
            GetSQLValueString($_POST['From'], "text"), 
            GetSQLValueString($_POST['To'], "text"), 
            GetSQLValueString($_POST['NoOfPass'], "int"), 
            GetSQLValueString($_POST['DateMonth'], "text"), 
            GetSQLValueString($_POST['Day'], "int"), 
            GetSQLValueString($_POST['Time'], "text"));

    mysql_select_db($database_Connection, $Connection);
    $Result1 = mysql_query($insertSQL, $Connection) or die(mysql_error());

    $insertGoTo = "confirmation.php";
    if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
}
?>
Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
Michael Lau
  • 149
  • 1
  • 1
  • 10
  • possible duplicate of [Headers already sent by PHP](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – Yogesh Suthar Aug 20 '13 at 04:51

2 Answers2

0

make sure your code, don't do echo statement when you are using the header for redirection, and put the exit(); next line to the header statement.

like

//echo 'do not do echo statement here'; if you uncomment this block you will get the same error again.
header('your location here');
exit();
sudhakar
  • 582
  • 1
  • 3
  • 13
  • it still gives the same problem Warning: Cannot modify header information - headers already sent by (output started at /srv/disk2/1201823/www/-----------.org/Florida/bookingV1.php:1) in /srv/disk2/1201823/www/-----------.org/Florida/bookingV1.php :(( – Michael Lau Aug 20 '13 at 05:05
  • have you checked all your files? i mean all functions and included files, checked this file with header only.then include all your code its just for debugging your code – sudhakar Aug 20 '13 at 05:12
0

There should be no output before sending the headers.

According to the error report you're getting, there is something being outputted in the 1st line of the "bookingV1.php" script, which leads me to believe that the problem is a leading whitespace, text or HTML before the opening <?php marker.

Community
  • 1
  • 1
federico-t
  • 12,014
  • 19
  • 67
  • 111