1

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.

4
  • You have a space at the end of echo<<<EOD remove it and it will work, just as Phil stated below. Commented Nov 19, 2013 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. Commented Nov 19, 2013 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 Commented Nov 19, 2013 at 5:17
  • I learned something new tonight, noted. @Phil Commented Nov 19, 2013 at 5:18

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately, when I edited the space, it made no difference.
@rsheeler You appear to have a tab or some other whitespace character (other than a newline) after <<<EOD
@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 ;-)
0

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;

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.