SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: PHP Problem

  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Problem

    Hi There

    I think I am going a bit nuts. I am following along with Kevin Yanks book on Build Your Own Database Driven Websites.

    I have tried programming the examples myself as well as uploading the code archive to my localserver.

    But I get the same warning with the following script

    PHP Code:
    <?php
    include_once $_SERVER['DOCUMENT_ROOT'] .
            
    '/includes/magicquotes.inc.php';

    if (isset(
    $_GET['add']))
    {
        
    $pagetitle 'New Author';
        
    $action 'addform';
        
    $name '';
        
    $email '';
        
    $id '';
        
    $button 'Add author';

        include 
    'form.html.php';
        exit();
    }

    if (isset(
    $_GET['addform']))
    {
        include 
    $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

        
    $name mysqli_real_escape_string($link$_POST['name']);
        
    $email mysqli_real_escape_string($link$_POST['email']);
        
    $sql "INSERT INTO author SET
                name='
    $name',
                email='
    $email'";
        if (!
    mysqli_query($link$sql))
        {
            
    $error 'Error adding submitted author.';
            include 
    'error.html.php';
            exit();
        }

        
    header('Location: .');
        exit();
    }
    The warning that I get is
    Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/chapter4G/authors/index.php:1) in /Applications/XAMPP/xamppfiles/htdocs/php/chapter4G/authors/index.php on line 27

    The code that I have pasted at the top of the page is the line 1 in my PHP file.

    The header('Location: .'); is not in any other code.

    Can someone help please.

    G

  2. #2
    SitePoint Zealot behati's Avatar
    Join Date
    Feb 2012
    Location
    Copenhagen, Denmark
    Posts
    152
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Did you try to debug it? using things like:

    ini_set(‘display_errors’, true);
    ini_set(‘display_startup_errors’, true);
    error_reporting (E_ALL);
    output_buffering = On in php.ini

    Also, your included PHP script is maybe sending the headers before your actual page?

    This is an annoying error that happens all the time.. I often bypass it by overriding the standard header and setting it manually.. but of course finding the real problem and solving it is better..

    Make sure nothing is above your initial PHP code (not even HTML) or try surrounding your PHP code with:
    <? ob_start(); ?>

    then at the bottom of the page place this line of code:

    <? ob_flush(); ?>

    Hope any of that helps


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
  •