glassfish Posted October 10, 2014 Share Posted October 10, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/ Share on other sites More sharing options...
mac_gyver Posted October 10, 2014 Share Posted October 10, 2014 Does anybody have a suggestion how to solve this issue? yes, you are not the first person to ever have errors in your php code. if you search the web for that very common error message, you will find what it means and what to do to to find what is causing it. Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/#findComment-1493259 Share on other sites More sharing options...
Jacques1 Posted October 10, 2014 Share Posted October 10, 2014 The code you've posted has trailing whitespace all over the place, which breaks the heredoc syntax. You need to make your editor/IDE remove excess whitespace, preferrably each time the file is saved. Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/#findComment-1493260 Share on other sites More sharing options...
mac_gyver Posted October 10, 2014 Share Posted October 10, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/#findComment-1493261 Share on other sites More sharing options...
glassfish Posted October 10, 2014 Author Share Posted October 10, 2014 (edited) 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 October 10, 2014 by glassfish Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/#findComment-1493266 Share on other sites More sharing options...
Solution Ch0cu3r Posted October 10, 2014 Solution Share Posted October 10, 2014 $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; } Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/#findComment-1493268 Share on other sites More sharing options...
glassfish Posted October 10, 2014 Author Share Posted October 10, 2014 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/291561-unexpected-end-of-file/#findComment-1493270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.