Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I a creating a form where the user can update previously entered information in fields relative to an ID field.

However, I am getting a parse syntax error when using the HEREDOC method of displaying the modifications to the code.

My error displayed looks like this:

Parse error: syntax error, unexpected '<<' (T_SL) in /Applications/XAMPP/xamppfiles/htdocs/serverside/phptut/update.php on line 24

For reference my script on 24 onward looks like this:

echo<<<EOD 
    <b>The new record looks like this:</b>
    Email: $email<br/>
    First: $first<br/>
    Last: $last<br/>
    Status: $status<br/>
EOD;

And for further reference my code in totality is this

<?php
include "dbinfo.php";
//gets the variables from form submitted
$id = $_POST[id];
$email = $_POST[email];
$first = $_POST[first];
$last = $_POST[last];
$status = $_POST[status];

//sets the values where the ID is equal to what was passed in 
$sql = "UPDATE contacts SET
email = '$email',
first ='$first',
last = '$last',
phone ='$phone'
where ID = '$id' ";

$result = mysql_query($sql) or die(mysql_error());
//excute

//print what the new one looks like
echo '<html><head><title>Updated Results</title></head><body>';
include ("header.php");
echo<<<EOD 
    <b>The new record looks like this:</b>
    Email: $email<br/>
    First: $first<br/>
    Last: $last<br/>
    Status: $status<br/>
EOD;

?>

Any help would be greatly appreciated.

share|improve this question
 
@Fred-ii- You most certainly do not –  Phil Nov 19 at 4:59
 
You have a space at the end of echo<<<EOD remove it and it will work, just as Phil stated below. –  Fred -ii- Nov 19 at 5:14
 
Well, when I copied the OP's code, it was a space. @Phil least, that's what it showed up as, as single character if I can say. –  Fred -ii- Nov 19 at 5:16
 
@Fred-ii- Never mind, vi identified it as trail which I took to mean a different character. It is in fact a trailing space –  Phil Nov 19 at 5:17
 
I learned something new tonight, noted. @Phil –  Fred -ii- Nov 19 at 5:18

2 Answers

See HEREDOC

A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline.

There should not be a space between <<< and the identifier and there should only be a newline after. You a single, trailing space character after <<<EOD.

Working demo here - http://codepad.org/Y2vxavDB

Also, please be aware that the MySQL extension has been deprecated. You should be using MySQLi or PDO.

share|improve this answer
 
Unfortunately, when I edited the space, it made no difference. –  rsheeler Nov 19 at 4:48
1  
@rsheeler You appear to have a tab or some other whitespace character (other than a newline) after <<<EOD –  Phil Nov 19 at 5:02
 
@Phil I figured it out for myself, and you're right. The OP obviously has a white space after EOD and/or after the end. Actually I'm glad you didn't tell me the "why", because I actually like to figure things out for myself ;-) –  Fred -ii- Nov 19 at 5:12

The closing identifier must begin in the first column of the line.

Here is another Example http://codepad.org/FobMK0AL

<?php
echo<<<EOD
<b>The new record looks like this:</b>
Email: $email<br/>
First: $first<br/>
Last: $last<br/>
Status: $status<br/>
EOD;

?>
share|improve this answer
1  
Annnnnd. it worked! :) Thank you! –  rsheeler Nov 19 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.