www.webdeveloper.com
Results 1 to 3 of 3

Thread: Am I using header function incorrectly?

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Am I using header function incorrectly?

    Hi!

    I'm using this header('Location:index.php'); to get my page reload after user press the submit button.

    PHP Code:

    if(isset($_POST['submit'])) {
                                        
       
    $comment $_POST['comment'];
       
    $writer $_POST['writer'];                                   
       
    $date_and_time date('Y-m-d H:i:s');
                                        
       
    mysql_query("INSERT INTO comment (writer, comment, date_and_time)
                          VALUES ('
    $writer', '$comment', '$date_and_time')")
                        or die(
    mysql_error());
                                        
       
    header('Location:index.php');
                                        

    It's working like a charm, but if you take a look at the PHP manual there is: "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP".

    So am I doing something very wrong or not ?

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    no you are doing all fair as there is no output before header(); function at all.

  3. #3
    Join Date
    Mar 2012
    Posts
    62
    Hi

    At top file

    add <?php ob_start(); ?>

    and check it now

    Thanks
    masterwin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles