-1

Hey getting an error on my code can anyone tell me how to fix it?

Notice: Use of undefined constant folder - assumed 'folder' in C:\xampp\htdocs\a\gallery.php on line 74

Notice: Use of undefined constant folder - assumed 'folder' in C:\xampp\htdocs\a\gallery.php on line 75

Here's the relevant section

     $path = "./images/gallery";
  $results = scandir($path);

  foreach ($results as $result) {
    if ($result !== "." and $result !== ".." and $result !== ".DS_Store"){
    //only lists the folders we want

        $folders[] = $result;
      } 
  }

  echo "<h2 id=\"galleryheaders\">";

    foreach ($folders as $folder){
      echo "<a href=\"gallery.php?folder=$folder\">$folder</a>\n";
    }



  foreach ($folders as $folder){
      echo "<?gallery = . $folder>";

    }

  echo "</h2>";

  if (isset($_GET[folder])) {
    $gallery = $_GET[folder];
  }else { 
    $gallery = $folders[0];
    };

the lines it specifically mentions are those last 2 folders

5
  • Try this echo "<a href=\"gallery.php?folder=".$folder."\">".$folder."</a>\n"; in place of echo "<a href=\"gallery.php?folder=$folder\">$folder</a>\n"; Commented May 7, 2015 at 21:31
  • Which are lines 74 and 75? Commented May 7, 2015 at 21:32
  • 1
    Are you sure this is line 74-75? I don't see anything from my understanding that would generate this notice. Normally, it's generated when you forget to prefix a variable with $, and PHP assumes it's a constant. Commented May 7, 2015 at 21:33
  • Quote your associative array indexes, otherwise PHP assumes that an unquoted text value is a constant: if (isset($_GET['folder'])) { $gallery = $_GET['folder']; }else { $gallery = $folders[0]; }; Commented May 7, 2015 at 21:33
  • Please note what you changed in your original comment. Relevant code was added. Commented May 7, 2015 at 21:34

1 Answer 1

3

You forgot the quotes around your strings:

if (isset($_GET[folder])) {
    $gallery = $_GET[folder];
}

should be:

if (isset($_GET['folder'])) {
    $gallery = $_GET['folder'];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.