Hi,

I am trying to create an image gallery for my site. I am using the following code, but when I try to load the page I get the following error:

Parse error: syntax error, unexpected T_SL in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/preupload.php on line 15

Can anybody tell me why I am getting this message and how I fix the problem?

Any help would be very much appriciated.

<?php 
 include 'config.inc.php'; 

 // initialization 
 $photo_upload_fields = ''; 
 $counter = 1; 

 // If we want more fields, then use, preupload.php?number_of_fields=20 
 $number_of_fields = (isset($_GET['number_of_fields'])) ? 
   (int)($_GET['number_of_fields']) : 5; 

 // Firstly Lets build the Category List 
 $result = mysql_query('SELECT category_id,category_name FROM gallery_category'); 
 while($row = mysql_fetch_array($result)) { 
   $photo_category_list .= <<<__HTML_END (THIS IS LINE 15)
<option value="$row[0]">$row[1]</option>\n 
__HTML_END; 
 } 
 mysql_free_result( $result );   

 // Lets build the Image Uploading fields 
 while($counter <= $number_of_fields) { 
   $photo_upload_fields .= <<<__HTML_END 
<tr><td> 
 Photo {$counter}: 
 <input name="photo_filename[]" 
type="file" /> 
</td></tr> 
<tr><td> 
 Caption: 
 <textarea name="photo_caption[]" cols="30" 
   rows="1"></textarea> 
</td></tr> 
__HTML_END; 
   $counter++; 
 } 

 // Final Output 
 echo <<<__HTML_END 
<html> 
<head> 
<title>Lets upload Photos</title> 
</head> 
<body> 
<form enctype="multipart/form-data" 
 action="upload.php" method="post" 
 name="upload_form"> 
 <table width="90%" border="0" 
   align="center" style="width: 90%;"> 
   <tr><td> 
     Select Category 
     <select name="category"> 
     $photo_category_list 
     </select> 
   </td></tr> 
   <!—Insert the image fields here --> 
   $photo_upload_fields 
   <tr><td> 
     <input type="submit" name="submit" 
       value="Add Photos" /> 
   </td></tr> 
 </table> 
</form> 
</body> 
</html> 
__HTML_END; 
?>

    That sort of error usually implies a missing '{' or ';'. Which is line 15? Look at the few lines before that line for clues...

    Hint: use the board's PHP tags when you post code. It makes it much, much easier to read and people are more likely to help you.

      Hi thanks for your suggestion.

      I've added a note inn brackets to identify line 15.

      Any suggestions?

      Thanks

        Interesting: the heredoc manual entry says "...the identifier used must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore." However, my testing would seem to indicate that the parser does not like any underscores in the identifier (whether the first character or elsewhere in the string). So it would seem the work-around is to use something like the following without any underscores:

        $photo_category_list .= <<<HTMLEND
        blah blah blah
        HTMLEND;
        

          Hi thanks for your suggestion.

          I've tried that but I'm still getting the same error message.

          Do you have any other suggestion?

            You are not allowed spaces after the name of the heredoc section either on the starting line or the ending line. You have them in both locations.

            As for using an underscore as the start character, I always use one and have never had a problem.

              rincewind456 wrote:

              You are not allowed spaces after the name of the heredoc section either on the starting line or the ending line. You have them in both locations.

              As for using an underscore as the start character, I always use one and have never had a problem.

              Hmmm...you appear to be correct. Maybe there was a white-space character that I unwittingly deleted when testing the original code? Anyway, the following worked fine for me except the last case, where I added a space after the identifier, so I guess I was mistaken/confused:

              <?php
              $text = <<< HTMLEND
              This is a test.
              HTMLEND;
              $text .= <<< __HTML_END
              It is only a test.
              __HTML_END;
              $text .= <<< SPACE_AFTER_THIS 
              This one will fail, as there is a space at the end of 'SPACE_AFTER_THIS '.
              SPACE_AFTER_THIS;
              echo $var;
              ?>
              

                Yeh that's done the trick.

                Thanksyou all for your help.

                  Write a Reply...