Jump to content

I cant see what the error is?


tzv111

Recommended Posts

I have a function and within that some code which is recalling some information from a database, however i keep getting an error stating

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_u003753/public_html/assesment/functions.php on line 61

 

 

function guestList(){
$guessContent = <<<GUESTS
<div id="left">
<h2>Guestlist created</h2>
include 'database_conn.php';
$sql = "SELECT * FROM guestlist";
$queryresult = mysql_query($sql)
or die(mysql_error());
while ($row = mysql_fetch_assoc($queryresult)){
$guestID = $row['guestID'];
$surName= $row['surName'];
$firstName = $row['firstName'];
$number = $row['number'];
echo "guestID: $guestID<br />";
echo "surName: $surName<br />";
echo "firstName: $firstName<br />";
echo "number: $number<br />";
echo "<hr />";
</div>
GUESTS;
$guestContent .= "\n";
return $guestContent;
}

 

 

 

Line 61 is

$guestID = $row['guestID'];

 

any help would be greatly appreciated

 

 

Link to comment
https://forums.phpfreaks.com/topic/181612-i-cant-see-what-the-error-is/
Share on other sites

I have tried placing it outside of the HEREDOC this fixes that initial problem, but I then don't know how to wrap the divs around the database retrieval code. I have tried many different methods but If I place the Divs outside of a HEREDOC they produce errors

You only need to use heredoc within the while loop.

function guestList()
{
    $guessContent = <<<GUESTS
  <div id="left">
    <h2>Guestlist created</h2>
GUESTS;

    include 'database_conn.php';

    $sql = "SELECT * FROM guestlist";
    $queryresult = mysql_query($sql) or die(mysql_error());

    while ($row = mysql_fetch_assoc($queryresult))
    { // start while loop
        $guestID = $row['guestID'];
        $surName= $row['surName'];
        $firstName = $row['firstName'];
        $number = $row['number'];

        $guestContent .=  <<<GUESTS
   guestID: $guestID<br />
   surName: $surName<br />
   firstName: $firstName<br />
   number: $number<br />
     <hr />
  </div>
GUESTS;
    } // end while loop

    $guestContent .= "\n";
    return $guestContent;
}

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.