Php <<<END statement error when link with mysql ..Please help

Discussion in 'PHP' started by harpuneetthind, Feb 16, 2012.

  1. #1
    <h1>Members List</h1>

    <table border="1">
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Country</th>
    <th>College</th>
    </tr>
    <?php

    // Open a connection to the database
    //Using PHP with MySQL

    $link = mysqli_connect('localhost', 'pal', '123456', 'globall');
    // Define a query that retrieves the first name and last
    // name of every employee
    $query = "SELECT name, lastname, country, college FROM users";

    // Run the query and store the result
    $result = mysqli_query($link, $query);

    // Close the connection to the database
    mysqli_close($link);


    // Assign each record in the result to an array
    while ($row = mysqli_fetch_array($result)) {

    // Assign each database array element to a variable
    $name = $row['name'];
    $lastname = $row['lastname'];
    $country = $row['country'];
    $college = $row['college'];


    // Display each record in a separate row of the table
    echo <<<END
    <tr>
    <td>$name</td>
    <td>$lastname</td>
    <td>$country</td>
    <td>$college</td>
    </tr>
    END;
    }
    ?>
    </table>


    I am getting error when running this code on my localhost.
    Parse error: syntax error, unexpected T_SL in C:\xxx\xampp\htdocs\user.php on line 49

    Line 49 is echo <<<END
     
    harpuneetthind, Feb 16, 2012 IP
  2. BigTim3

    BigTim3 Guest

    Messages:
    266
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    0
    #2
    try somethning like this
    print
     
    BigTim3, Feb 17, 2012 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    please use code tags!
    please submit to the right forum.

    print, sprint, printf, echo :)

    AND PLEASE don't close the connection before you have got all information you want.

    So put
    // Close the connection to the database
    mysqli_close($link);

    at the end of your script!
     
    EricBruggema, Feb 18, 2012 IP