Jump to content

Getting an error with HEREDOC


Jragon

Recommended Posts

My error:

Parse error: syntax error, unexpected T_START_HEREDOC in C:\xampp\htdocs\movie\table2.php  on line 22

 

My code:

<?php
    //connect to mysql
    include("connect.php");

    //make sure your using the right database
    mysql_select_db('moviesite') or die(mysql_error);

    //retrive information
    $query = 'SELECT
            movie_name, movie_year, movie_director, movie_leadactor, movie_type
        FROM
            movie
        ORDER BY
            movie_name ASC,
            movie_year DESC';
    $result = mysql_query($query) or die(mysql_error);

    //determine number of rows in returned result
    $num_movies = mysql_num_rows($result);

    $table <<<ENDHTML
    <div align="center">
    <h2>Movie Review Database</h2>
    <table border="1" cellpadding="2" cellspacing="2" style="width: 70%; margin-left: auto; margin-right: auto;">
        <tr>
            <th>Movie Title</th>
            <th>Year of Release</th>
            <th>Movie Director</th>
            <th>Movie Lead Actor</th>
            <th>Movie Type</th>
        </tr>
        <?php
        //loop through the results
        while ($row = mysql_fetch_assoc($result)){
            extract($row);
            $table .= <<<ENDHTML
            <tr>
                <td>$movie_name</td>
                <td>$movie_year</td>
                <td>$movie_director</td>
                <td>$movie_leadactor</td>
                <td>$movie_type</td>
            </tr>
            ENDHTML;
        }

    $table .= <<<ENDHTML
    </table>
    <p>$num_movies Movies</p>
    </div>
    ENDHTML;
?>

 

Please tell me what went wrong

Link to comment
https://forums.phpfreaks.com/topic/206925-getting-an-error-with-heredoc/
Share on other sites

You're also going to get one here:

 

 </tr>
            ENDHTML;

 

Because there can't be any whitespace before the end of the heredoc block.  Needs to be:

 

 </tr>
ENDHTML;

 

Also, that heredoc with the while loop in it is going to cause issues.  You may have some things disorganized.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.