• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

PHP parse error

I get the following error in the script below, I can't figure out what's wrong.
Can anyone tell me?
Note: comments have been removed and line numbers don't match but the offending line has a lot of ***********, the curly bracket was all there was on that line

[client] PHP Parse error:  parse error, unexpected '{' in /home/meeting/chair/display_tree.php on line 31, referer:

<? session_start(); ?>
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head><title>Select files</title>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<body background='wp2c.png'>
<table class='tabl01'><tr><td width='100%'>
<h2>Directories and files</h2>
if ( isset($_POST['submit']) && $_POST['submit'] == 'Working files have been selected.' ) {
  echo '<pre>';
  echo '</pre>';
  $_SESSION['files'] = $files;
  echo "<form action='makeit_rw.php'><input type='submit' name='submit1' value='Selection is     correct'></form>";
$dirs[0] = 'test';            # adjust for real life
while ( $dirs ) {
  $dir = opendir(reset($dirs));
  while ( ($file = readdir($dir)#) !== false )
    { //this is line 31 ********************************************
    if ( $file != '.' && $file !== '..' ) {
      if ( is_dir(current($dirs).'/'.$file) ) {
        $dirs[] = current($dirs).'/'.$file;
      } else
        $files[] = current($dirs).'/'.$file;
 $_SESSION['dirs'] = $dirs;
sort ($files);
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
foreach ( $files as $file )
  echo '<input type="checkbox" name="files[]" value="', $file, '">', $file, '<br/>';
<input type="submit" name="submit" value="Working files have been selected.">
  • 2
1 Solution
# is also a comment
Remove it from your while loop

 while ( ($file = readdir($dir)) !== false )
    { //this is line 31 **
BTW, this is good reason why I prefer to use an editor that understands php and color codes it.
Catching misplaced comments, inproperly terminated strings, mispelling of php functions, etc. become obvious because the code changes color for different elements. Dreamweaver's pretty good, Zend Studio is surely the best b/c it displays syntax errors similarly to the way Word Processors do. So most parse errors are caught before you ever execute your script.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now