Results 1 to 4 of 4

Thread: header() creating problem

  1. #1
    Join Date
    Sep 2009
    Location
    pakistan
    Posts
    28
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Exclamation header() creating problem

    Hi guys im using the following code query is executing n creating records in database but the page don't redirect to content.php. following is the code with the errir statement
    <?php
    $menuName = $_POST['menuName'];
    $position = $_POST['position'];
    $visibilty = $_POST['visibilty'];

    $query = "INSERT INTO subjects(
    menuName, position , visibilty
    ) VALUES(
    '{$menuName}',{$position},{$visibilty}
    )";

    if(mysql_query($query, $conection)){
    // succeded
    //echo "Subject creation successful";
    header("Location: content.php");
    exit;
    }else{
    // failed
    echo "<p>Subject creation failed</p>" ;
    echo "<p>". mysql_error() ."</p>";
    }
    ?>

    The error stament is
    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\widget\creat_subject.php

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You can't have any output to the browser before using the header(). If you need to have output beforehand then put this at the very top right after the opening php tag
    PHP Code:
    ob_start(); 

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It should always be possible (except in very special circumstances) to avoid output buffers.

    Headers must be sent before anything is output (including even blank lines) so just plan your structure accordingly.


    For example, you can just reverse these two lines:
    Code:
    header("Location: content.php");
    //echo "Subject creation successful";
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Sep 2009
    Location
    pakistan
    Posts
    28
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thanks with regards
    aqeel

Bookmarks

Posting Permissions

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