Jump to content

Unexpected End of File?


glassfish
Go to solution Solved by Ch0cu3r,

Recommended Posts

I am getting this error message:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\sitepoint\preupload.php on line 67

with this script:

<?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  
<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;  
?>
on line 67

It points to the closing tag:

?>

Does anybody have a suggestion how to solve this issue?

Link to comment
Share on other sites

i, in fact, don't get that error from your code, but then again, i typically remove leading and trailing white-space that you may have had in your file and that the forum software adds when it  (mis)formats code in posts.

 

you must be extremely careful about what comes before and after the starting and ending identifiers you use for the herdoc syntax.

Link to comment
Share on other sites

Okey, thanks guys, it worked.

 

And now, here, at this spot :

while($row = mysql_fetch_array($result)) {
    $photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>n
__HTML_END;
}

I get the following error:

Notice: Undefined variable: photo_category_list in C:\xampp\htdocs\sitepoint\preupload.php on line 26

I am not getting an error for the other variable "$photo_upload_fields". Why do I get an error for this variable?

 

EDIT:

Sorry, I totally missed it. It may happen because the database is empty.

Edited by glassfish
Link to comment
Share on other sites

  • Solution

$photo_category_list will not be defined on the first iteration of the while loop. This is why you are getting that notice. PHP is attempting to concatenate a value onto a variable which is not defined yet. To prevent the notice initialize the variable before the while loop

$photo_category_list = ''; // initialize variable to empty string
while($row = mysql_fetch_array($result)) {
    $photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>n
__HTML_END;
}
Link to comment
Share on other sites

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.