Newbie: form with a dynamic php drop down.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dakke
Forum Newbie
Posts: 24
Joined: Fri Aug 10, 2007 6:34 pm

Newbie: form with a dynamic php drop down.

Post by Dakke »

Well, I could not find a topic/tutorial where they explain what Im trying to. I have a php script pulling data from a DB, and display that in a dropdown menu. Works just fine.

The only thing is, I would like to create a form that shows this php file/dropdown. I can 'include' the php file and it shows the actual drop down. But it also shows an empty dropdown, most likely (I guess) due to the html code.:

Code: Select all

 
<td>Series in English: 
    <select id="serie_id" name="series_english"> 
        <?php include('php/DropdownSeries.php'); ?>
    </select><br><br><br><br>
</td>
 
But how do you integrate a php file with a form? What I try to do is to show the dropdown, user selects and value gets posted. How does on do that?

I posted the code for the dropdown, cause it might just be part of the problem:

Code: Select all

 
<?php
 
// Open DB
include("library/config.php");
include("library/opendb.php");
 
 
  // Query the series table and load all of the records
  // into an array.
  $sql = 'SELECT series_english FROM series';
  $res = mysql_query($sql) or die(mysql_error());
  while ($rec = mysql_fetch_assoc($res)) $series[] = $rec;
 
  // die('<pre>'.print_r($series));
 
  echo '<SELECT name="dropdown">';
  foreach ($series as $c)
  {
    if ($c['id'] == $_GET['id'])
      echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['series_english']}</OPTION>\n";
    else
      echo "<OPTION value=\"{$c['id']}\">{$c['series_english']}</OPTION>\n";
  }
  echo '</SELECT>';
?>
 
Post Reply