Topic: Parse error: syntax error, http://www.zend.com/zend/trick/tricks-jan-2003.php (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=29637" title="Pages that link to Topic: Parse error: syntax error, http://www.zend.com/zend/trick/tricks-jan-2003.php (Page 1 of 1)" rel="nofollow" >Topic: Parse error: syntax error, http://www.zend.com/zend/trick/tricks-jan-2003.php <span class="small">(Page 1 of 1)</span>\

 
macunkie
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Oct 2007

posted posted 10-21-2007 13:31

I've been working (attempting) to work through the tutorial on building a photo album relative to http://www.zend.com/zend/trick/tricks-jan-2003.php.

I'm experiencing the following error when trying to access my "addphoto.php" page:

ERROR = Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Volumes/Storage/webdocs/addphoto.php on line 33

My code is as follows:

code:
<?php 
include "album_config.inc.php"; 

// Use Heredoc syntax to format the XHTML form 
$addPhotoForm = <<< addPhotoForm
<p>Add a photo to the album</p> 
<form action="addphoto.php"  
enctype="multipart/form-data" method="post"> 
     <p> 
          Photo:<br /> 
          <input name="photo" type="file" /> 
     </p> 

     <p> 
          Descriptive Title:<br /> 
          <input type="text" name="title"  
          size="40" maxlength="80" value="" /> 
     </p> 

     <p> 
          Description:<br /> 
          <textarea name="description"  
          rows="3" cols="40"></textarea> 
     </p> 

     <p> 
          <input type="submit" value="Add photo!" /> 
     </p> 
</form> 
addPhotoForm; 

// If the user has submitted a file for uploading. 
if (is_uploaded_file($_FILES['photo']['temp_name'])) {
    # Add the photo to the MySQL database 
    add_photo($_FILES['photo']['name'], $_POST['title'],  
    $_POST['description']) or die("couldnt add photo"); 
    # Move the photo from the temp directory to 
    # the images directory. 
    move_uploaded_file($_FILES['photo']['temp_name'], 
    ABSOLUTE_PATH.$_FILES['photo']['name']); 

    echo "<p>The photo was successfully uploaded .</p>"; 

} 
// display the form on every page instance 
echo $addPhotoForm; 
?>




Further explanation of my attempt to solve the problem can be found in this post:
http://www.zend.com/forums/index.php?t=msg&goto=13750&S=06294dcf8200386464cc9179b583e47a#msg_13750

Can anyone help me understand why I can't get past the error?

Thanks for any help,

MacUnkie

Edit Tyberius Prime: Code tags are a good idea, let's have more of those

(Edited by Tyberius Prime on 10-21-2007 13:51)

(Edited by macunkie on 10-21-2007 13:53)

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-21-2007 13:58

$addPhotoForm = <<< addPhotoForm
should read
$addPhotoForm = <<<addPhotoForm


And no matter what the doc says, apperantly the semicolon must be
in the line after the heredoc string.

Honestly, you're better off using ' instead of the (unusual) heredoc syntax.

code:
<?php
include("album_config.inc.php");

// Use Heredoc syntax to format the XHTML form 
$addPhotoForm = 'addPhotoForm
<p>Add a photo to the album</p> 
<form action="addphoto.php"  
enctype="multipart/form-data" method="post"> 
     <p> 
          Photo:<br /> 
          <input name="photo" type="file" /> 
     </p> 

     <p> 
          Descriptive Title:<br /> 
          <input type="text" name="title"  
          size="40" maxlength="80" value="" /> 
     </p> 

     <p> 
          Description:<br /> 
          <textarea name="description"  
          rows="3" cols="40"></textarea> 
     </p> 

     <p> 
          <input type="submit" value="Add photo!" /> 
     </p> 
</form> 
';

// If the user has submitted a file for uploading. 
if (is_uploaded_file($_FILES['photo']['temp_name'])) {
    # Add the photo to the MySQL database 
    add_photo($_FILES['photo']['name'], $_POST['title'],  
    $_POST['description']) or die("couldnt add photo"); 
    # Move the photo from the temp directory to 
    # the images directory. 
    move_uploaded_file($_FILES['photo']['temp_name'], 
    ABSOLUTE_PATH.$_FILES['photo']['name']); 

    echo "<p>The photo was successfully uploaded .</p>"; 

} 
// display the form on every page instance 
echo $addPhotoForm; 
?>



So long,

->Tyberius Prime

macunkie
Obsessive-Compulsive (I) Inmate

From:
Insane since: Oct 2007

posted posted 10-21-2007 20:38

Thank you for your reply.

The

quote:
ERROR = Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Volumes/Storage/webdocs/addphoto.php on line 33

is referring to
the line of code:
ERROR = Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Volumes/Storage/webdocs/addphoto.php on line 33

I'm trying to understand this error.

Thank for your help,

MacUnkie.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-21-2007 20:47

Your problem is that the line in the error code is where the error is detected,
which often is not where the error is actually caused.

Your error is being caused by two seperate problems:
a) you have a space between <<< and your terminator
and
b) the heredoc terminator handling is fiddly. The terminator either needs to be on a line by itself,
or on a line with nothing but the terminator and the semicolon. And you have a space after the semicolon...

now both errors are before line 33, but
line 33 is where php sees the first problem, because if you were to use
$_FILES['photo']['temp_name'] within a heredoc string (or any string for that matter),
you'd need to wrap it in {} like $_FILES['photo']['temp_name'].
But that's not the error, it's just where it first manifests as a real parser error.

Long story short:
Line numbers are an upper limit to 'position of my typo'.

so long,

->Tyberius Prime

macunkie
Obsessive-Compulsive (I) Inmate

From:
Insane since: Oct 2007

posted posted 10-21-2007 23:39

Thanks a bunch Tyberius!
Your code works!

I'm crossing my fingers on the rest of the tutorial.

MacUnkie.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu