Jump to content
Larry Ullman's Book Forums

Recommended Posts

Ok I haven't followed the code 100% by which I mean only that I didn't include the XHTML parts in the <!DOCTYPE> tag. I understand that this is not vital however. Other than that I think I have followed it correctly. I keep getting http error 500 in the browser however when I try to load it. However other php scripts seem to load fine so I don't think it's a problem with MAMP.

Here is my code: 

 

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" http-equiv="Content-Type" content="text/html">
    <title>Calendar</title>
  </head>
  <body>
    <form action="calendar.php" method="post">
      <?php # Script 2.6 - Calendar.php
      //This script makes 3 pulldown menus
      //For an html form: months, days, years.
 
      //make months array
        $months = array (1 => 'January', 'February', 'March', 'April', 'May',
        'June', 'July', 'August', 'September', 'October', 'November',
        'December');
 
      //make the days and years array
        $days = range (1, 31);
        $years = range (2011, 2021);
 
      //make the months pull down menu:
        echo '<select name="month">';
        for each ($months as $key => $value) {
          echo "<option value=\"$key\">$value</option>\n";
        }
        echo '</select>';
 
      //make the days pull-down menu:
        echo '<select name="day">';
        foreach ($days as $value) {
          echo "<option value=\"$value\">$value</option>\n";
        }
        echo '</select>';
 
      //make the years pull-down menu:
        echo '<select name="year">';
        foreach ($year as $value) {
          echo "<option value=\"$value\">
            $value</option>\n";
        }
        echo "</select>";
      ?>
    </form>
  </body>
</html>

It's probably something incredibly obvious and embarrassing but any help would be gratefully received. I'm going to skip ahead and read the section of bug fixing while I wait for a response so maybe I will find the answer there. 

Thanks in advance.
 

 

Link to comment
Share on other sites

Line 24.....

You have for each, this should read foreach

 

Line 20...

You have $year, but on line 38 you are calling $years.

 

Change line 38 to read as follows:

foreach ($years as $value) {

 

Hope this helps.

Edited by larryjsr
Link to comment
Share on other sites

  • 1 month later...
 Share

×
×
  • Create New...