Jump to content

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;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.