Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: PHP Error Help

  1. #1
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default PHP Error Help

    I've been coding a php script and I've used session and I cannot figure out why I'm getting this error, help:

    PHP Code:
    Warningsession_start() [function.session-start]: Cannot send session cache limiter headers already sent (output started at C:\xampp\htdocs\PHP-Testing\FORM\backend\index.php:10in C:\xampp\htdocs\PHP-Testing\FORM\backend\data.php on line 6 
    My Code:
    PHP Code:
     <br />
    <center>
    <?php

      
    // Session Start
    session_start();

      
    // If logged in - view data
    if ($_SESSION['username'])
    {
      
    // Data
    include("../require.php");
        
    $connect = @mysql_connect$host$user$pass );
        
        if ( !
    $connect )
        {
        
            die( 
    'Could not connect: ' mysql_error() );
        
        }
        
        
    $select = @mysql_select_db$database$connect );
        
        if ( !
    $select )
        {
        
            die( 
    'Could not choose db: ' mysql_error() );
        
        }

        
    $result mysql_query"SELECT * FROM `questions`" );
        
        echo 
        
    '
         <table border="1">
            <tr>
                <th>Name</th>
                <th>Email</th>
            <th>ID</th>
                <th>Question</th>
            </tr>
        '
    ;


        while ( 
    $row mysql_fetch_array$result ) )
        {
        
            echo 
            
    '
            <tr>
                <td>' 
    $row['Name'] . '</td>
                <td>' 
    $row['Email'] . '</td>
                <td>' 
    $row['id'] . '</td>
                <td>' 
    $row['Question'] . '</td>
                <td><a href="index.php?page=data&delete=' 
    $row['id'] . '">Delete</a></td>
            </tr>
            '
    ;
        
        }
        
        echo 
        
    '
        </table><br /><br />
        '
    ;

        
    $delete mysql_real_escape_string$_GET['delete'] );
        
        if ( 
    $delete )
        {
        
            if ( 
    is_numeric$delete ) )
            {
            
                
                
    $check mysql_query"SELECT * FROM `questions` WHERE `id` = '{$delete}'" );
                
    $num mysql_num_rows$check );
                
                if ( 
    $num )
                {
                
                    
    mysql_query"DELETE FROM `questions` WHERE `id` = '{$delete}'" );
                    echo 
    'Question ID: ' $delete ' has been deleted! Refresh the page.';
                    
                }
                else
                {
                
                    echo 
    'Question ID does not exist!';
                
                }
                
            }
            else
            {
            
                echo 
    'Question ID must be a number!';

            }
            
        }

        
    mysql_close$connect );


    }
     else
      die(
    "You must sign in before viewing this page! <br> <a href='index.php'>Sign in now.</a>")
    ?></center>

  2. #2
    Join Date
    Jul 2008
    Location
    Devon
    Posts
    290
    Tokens
    0

    Default

    Hi!

    session_start() needs to be at the very top. PHP will output this error if there's any characters previous to this function, including white space.

  3. #3
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    Changed it so it goes:
    PHP Code:
    <?php
    session_start
    ();
    It just changes and says "Line 2".

  4. #4
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    PHP Code:
    <?php

      
    // Session Start
    session_start();

    ?>
     <br />
    <center>
    <?php
      
    // If logged in - view data
    if ($_SESSION['username'])
    {
      
    // Data
    include("../require.php");
        
    $connect = @mysql_connect$host$user$pass );
        
        if ( !
    $connect )
        {
        
            die( 
    'Could not connect: ' mysql_error() );
        
        }
        
        
    $select = @mysql_select_db$database$connect );
        
        if ( !
    $select )
        {
        
            die( 
    'Could not choose db: ' mysql_error() );
        
        }

        
    $result mysql_query"SELECT * FROM `questions`" );
        
        echo 
        
    '
         <table border="1">
            <tr>
                <th>Name</th>
                <th>Email</th>
            <th>ID</th>
                <th>Question</th>
            </tr>
        '
    ;


        while ( 
    $row mysql_fetch_array$result ) )
        {
        
            echo 
            
    '
            <tr>
                <td>' 
    $row['Name'] . '</td>
                <td>' 
    $row['Email'] . '</td>
                <td>' 
    $row['id'] . '</td>
                <td>' 
    $row['Question'] . '</td>
                <td><a href="index.php?page=data&delete=' 
    $row['id'] . '">Delete</a></td>
            </tr>
            '
    ;
        
        }
        
        echo 
        
    '
        </table><br /><br />
        '
    ;

        
    $delete mysql_real_escape_string$_GET['delete'] );
        
        if ( 
    $delete )
        {
        
            if ( 
    is_numeric$delete ) )
            {
            
                
                
    $check mysql_query"SELECT * FROM `questions` WHERE `id` = '{$delete}'" );
                
    $num mysql_num_rows$check );
                
                if ( 
    $num )
                {
                
                    
    mysql_query"DELETE FROM `questions` WHERE `id` = '{$delete}'" );
                    echo 
    'Question ID: ' $delete ' has been deleted! Refresh the page.';
                    
                }
                else
                {
                
                    echo 
    'Question ID does not exist!';
                
                }
                
            }
            else
            {
            
                echo 
    'Question ID must be a number!';

            }
            
        }

        
    mysql_close$connect );


    }
     else
      die(
    "You must sign in before viewing this page! <br> <a href='index.php'>Sign in now.</a>")
    ?></center>

  5. #5
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    I'll give that a try after school when I'm on my computer that has Xampp

  6. #6
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    I tend to but line breaks (<br />)'s in the echo rather than outside the php tags if its a full PHP page.

    The one that Blob posted should work.

    Lew.
    Im not here to be loved, I love to be hated :-}


  7. #7
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    It's being gayy.

    PHP Code:
    Warningsession_start() [function.session-start]: Cannot send session cache limiter headers already sent (output started at C:\xampp\htdocs\PHP-Testing\FORM\backend\index.php:10in C:\xampp\htdocs\PHP-Testing\FORM\backend\data.php on line 4 

  8. #8
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    I fixed that issue but now I'm trying to upload a demo and I keep getting this error.
    PHP Code:
    Parse errorsyntax errorunexpected T_STRINGexpecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/*USERNAME*1/public_html/scripts/jps/demo/insert.php on line 5 
    Here's my code:
    PHP Code:
    <?php
    include("require.php");
    $connect mysql_connect($host,$user,$pass) or die("<center><br />Couldn't connect to MySQL!</center><br />");
    mysql_select_db($database) or die("Couldn't connect to Database!");
    use 
    the_database_name

    $sql
    ="INSERT INTO questions (name, email, question)
    VALUES
    ('
    $_POST[name]','$_POST[email]','$_POST[question]')";

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "<center><br />Question submitted!</center><br />";

    mysql_close($con)
    ?>
    <br />

  9. #9
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    PHP Code:
    <?php
    include("require.php");
    $connect mysql_connect($host,$user,$pass) or die("<center><br />Couldn't connect to MySQL!</center><br />");
    mysql_select_db($database) or die("Couldn't connect to Database!");
    use 
    the_database_name

    $sql
    ="INSERT INTO questions (name, email, question)
    VALUES
    ('
    $_POST[name]','$_POST[email]','$_POST[question]')";

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "<center><br />Question submitted!</center><br />";

    mysql_close($con);
    ?>
    never even looked at the error properly, all I could see was the missing semi-colon on "mysql_close" - someone else will probably see whats actually up, been a while since I did PHP
    Last edited by Johno; 15-09-2010 at 12:28 PM.

  10. #10
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    Sorry. I pasted wrong error..
    Warning: mysql_connect() [function.mysql-connect]: Host '*HOST-REMOVED*' is not allowed to connect to this MySQL server in /home/*USER*/public_html/scripts/jps/demo/insert.php on line 3

Page 1 of 2 12 LastLast

Posting Permissions

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