title: HTML LISTBOXES & PHP
body: <p>I'm new to PHP, HTML &amp; web development in general.</p>
  
  <p>I was trying to get a listbox to read entries in from a associative array, which I managed to do.
  The problem is that, I can't seem to access the correct value, when an option is selected. It always seems generate the same response ("London"), regardless of which option is chosen. I tried replacing $city with ["listBox"], but the output was 'selected="selected"', $city seemed closer to what I was wanting, so I changed it back.</p>
  
  <p>I've spent a lot of time trying to figure out the reason why, if somebody can help me with this, I would appreciate it, thank you in advance.</p>
  
  <p>The code is below:</p>
  
  <pre><code>&lt;!DOCTYPE html lang="en"/&gt;`    
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Array Section: ex5.php&lt;/title&gt;
      &lt;charset = "utf-8"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;?php
          // Create an associate array 
          $countriesWithCities = array(
              "Japan" =&gt; "Tokyo",
              "Mexico" =&gt; "Mexico City",
              "USA" =&gt; "New York City",
              "India" =&gt; "Mumbai",
              "South Korea" =&gt; "Seoul",
              "China" =&gt; "Shanghai",
              "Nigeria" =&gt; "Lagos",
              "Brazil" =&gt; "Sao Paulo",
              "Egypt" =&gt; "Cairo",
              "England" =&gt; "London"
          );
          ?&gt;
          &lt;form action="ex5b.php" method="POST" /&gt;
          &lt;h1&gt;Ex5b.php &lt;/h1&gt;
          &lt;h3&gt;"listBox"&gt;Please choose a country from the list box. &lt;/h3&gt;
          &lt;select name="listBox" id="listBox" size="9" &gt;
              &lt;?php foreach ($countriesWithCities as $individualCountry =&gt; $city) { ?&gt;
                  &lt;option value= &lt;?php $city; ?&gt; selected="selected"&gt;
                      &lt;?php echo $individualCountry;
                      &gt;
                  } ?&gt;&lt;/option&gt;
          &lt;/select&gt;
  
          &lt;input type="submit" name="submitButton" id="submitButton" value="Submit form" /&gt;
          &lt;form&gt;
              &lt;?php
              if (isset($_POST["submitButton"])) {
                  echo "You chose " . $city;
              }
              ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>