understanding syntax errors

Hi all… I’m new to php and struggling badly.

I have written several very small scripts by hand and worked through any problems. Unfortunately I haven’t gained an understanding of why one attempt failed and another one worked.

Every example I grab off the internet seems to fail with syntax errors and I’m starting the get key impressions on my forehead because of pounding my head on the keyboard…

I’m not running any local PHP MySQL server because I can’t seem to get that working either…

The code, upload, test, recode, upload, test method I’ve been using is just not working for me with scripts that are over a few line long. Syntax errors produce a blank screen with no feedback as to what the problem is. I wasted a full day yesterday trying to get a relatively small script I got off the internet to run.

Thanks for bearing with me so far…

Two questions:

How do I get some feedback when running php scripts on my web server?

and

What is wrong with this script? (when I validate for syntax I get a T_Variable error at line #2)
[php]

<?php function folderlist(){ $startdir = 'masterfolder/documents/'; $ignoredDirectory[] = '.'; $ignoredDirectory[] = '..'; if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($folder = readdir($dh)) !== false){ if (!(array_search($folder,$ignoredDirectory) > -1)){ if (filetype($startdir . $folder) == "dir"){ $directorylist[$startdir . $folder]['name'] = $folder; $directorylist[$startdir . $folder]['path'] = $startdir; } } } closedir($dh); } } return($directorylist); } $folders = folderlist(); foreach ($folders as $folder){ $path = $folder['path']; $name = $folder['name']; echo '' . $name . '
'; } ?>

Hi buddy the problem is in your foreach syntex. See below

foreach( $employeeAges as $key => $value){
}

This is how you should use your foreach

Sponsor our Newsletter | Privacy Policy | Terms of Service