title: PHP Mysql submission form with cascading dropdowns
body: <p>I have been attempting to set up a submission form for my gaming community. We track ships in a game and I have got the form in shape. It is now submitting information correctly to the database; however, I am attempting to find a way to trim down the second drop down box to be dependent off the first. For example, I have provided the code for the form I am using and in it <strong>there are 5 fields</strong>; </p>
  
  <pre><code>Ship ID, 
  Ship Class,
   Ship Type,
   Ship Owner, 
  Ship Name.
  </code></pre>
  
  <p><strong>Ship Class and Ship Type are drop down boxes.</strong> </p>
  
  <p>I am looking to make them cascade so that if <strong>for example</strong> </p>
  
  <pre><code> I choose Battleship the second drop down would populate 
  with only Battleship 1, Battleship 2, and Battleship 3 and not the rest of fields
   in the second drop down. 
  </code></pre>
  
  <p>I have searched around google for a solution to this yet it seems to be eluding me, am I correct in assuming the second drop down must be based on relational tables? Also, would that need a separate query to do so?</p>
  
  <pre><code>    &lt;?php
      /* submit the application */
  
          /* get today's date */
          $today = getdate();
  
          /* build the insert query that's going to be used */
          $insert = "INSERT INTO ship_registry ( shipID, shipClass, shipType,  shipOwner, shipName ) ";
          $insert.= "VALUES ( %s, %s, %s, %s, %s ) ";
  
          /* run the query through sprintf and the safety function to scrub for   security issues */
          $query = sprintf(
              $insert,
              escape_string( $_POST['shipID'] ),
              escape_string( $_POST['shipClass'] ),
              escape_string( $_POST['shipType'] ),
              escape_string( $_POST['shipOwner'] ),
              escape_string( $_POST['shipName'] ),
              escape_string( $today[0] )
          );
  
          /* run the query */
          $result = mysql_query( $query );
      /* close the if statement on submitting the application */
  
      ?&gt;
  
      &lt;div class="body"&gt;
  
          &lt;?
  
          $check = new QueryCheck;
          $check-&gt;checkQuery( $result, $query );
  
          if( !empty( $check-&gt;query ) ) {
              $check-&gt;message( "entry", "submit" );
              $check-&gt;display();
          }
  
          ?&gt;
          &lt;span class="fontTitle"&gt;Submit Ship&lt;/span&gt;
          &lt;br /&gt;&lt;br /&gt;
  
          &lt;table&gt;
          &lt;form method="post" action="&lt;?=$webLocation;?&gt;index.php?page=addship"&gt;
              &lt;tr&gt;
                  &lt;td class="tableCellLabel"&gt;Ship ID&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&lt;input id="product" type="text" class="image" maxlength="7" name="shipID" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="tableCellLabel"&gt;Ship Class&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;select name="shipClass"&gt;
                          &lt;option value="Battleship"&gt;Battleship&lt;/option&gt;
                          &lt;option value="Battlecruiser"&gt;Battlecruiser&lt;/option&gt;
                          &lt;option value="Cruiser"&gt;Cruiser&lt;/option&gt;
                          &lt;option value="Destroyer"&gt;Destroyer&lt;/option&gt;
                          &lt;option value="Frigate"&gt;Frigate&lt;/option&gt;                
                      &lt;/select&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="tableCellLabel"&gt;Ship Type&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;select name="shipType"&gt;
                          &lt;option value="Battleship 1"&gt;Battleship 1&lt;/option&gt;
                          &lt;option value="Battleship 2"&gt;Battleship 2&lt;/option&gt;
                          &lt;option value="Battleship 3"&gt;Battleship 3&lt;/option&gt;
                          &lt;option value="Battlecruiser 1"&gt;Battlecruiser 1&lt;/option&gt;
                          &lt;option value="Battlecruiser 2"&gt;Battlecruiser 2&lt;/option&gt;
                          &lt;option value="Battlecruiser 3"&gt;Battlecruiser 3&lt;/option&gt;
                          &lt;option value="Cruiser"&gt;Cruiser&lt;/option&gt;
                          &lt;option value="Cruiser"&gt;Cruiser&lt;/option&gt;
                          &lt;option value="Cruiser"&gt;Cruiser&lt;/option&gt;
                          &lt;option value="Destroyer 1"&gt;Destroyer 1&lt;/option&gt;
                          &lt;option value="Destroyer 2"&gt;Destroyer 2&lt;/option&gt;
                          &lt;option value="Destroyer 3"&gt;Destroyer 3&lt;/option&gt;
                          &lt;option value="Frigate 1"&gt;Frigate 1&lt;/option&gt;
                          &lt;option value="Frigate 2"&gt;Frigate 2&lt;/option&gt;
                          &lt;option value="Frigate 3"&gt;Frigate 3&lt;/option&gt;                    
                      &lt;/select&gt;           
                  &lt;/td&gt;   
              &lt;/tr&gt; 
              &lt;tr&gt;
                  &lt;td class="tableCellLabel"&gt;Ship Owner&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" class="image" maxlength="64" name="shipOwner" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
                  &lt;tr&gt;
                  &lt;td class="tableCellLabel"&gt;Ship Name&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" class="image" maxlength="64" name="shipName" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                  &lt;td colspan="2"&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;strong class="yellow"&gt;Please make sure all information is entered correctly before submitting.&lt;/strong&gt;&lt;/b&gt;&lt;br /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="3" height="10"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="2"&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="image" src="&lt;?=$webLocation;?&gt;skins/&lt;?=$skinChoice;?&gt;/buttons/submit.png" name="action" class="button" value="Submit" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/form&gt;
          &lt;/table&gt;
  
  
      &lt;/div&gt; &lt;!--Close the div body class tag--&gt;
  </code></pre>