I've got a working dropdown pulling successfully from a MySQL table:

<p>Type: <select ="type"><?php

  $sql = "SELECT DISTINCT type, ID FROM fd_type ORDER BY ID DESC";
  $et = mysql_query($sql);
  while ($row = mysql_fetch_assoc($et)) {
      ?>
      <option value="<?php echo "$row[ID]" ?>" <?php if ($row['type'] == ($_REQUEST['type'])) echo 'selected'; ?>><?php echo $row['type'] ?></option><?php
  }
?>
</select>
*</p>

And I've got a successful statement to insert data into a table field:

<p>Type: <input type="text" name="type_ID" size="25" maxlength="100" value="<?php if (isset($_POST["$et"])) echo $_POST["$et"]; ?>" />
*</p>

The dropdown shows the information, but won't insert it, while the text box inserts the information, but doesn't have a dropdown (obviously). How do I combine the two?

The table that is providing the information for the dropdowns is linked to the main table (where I want to insert the data) by a foreign key (ID in the dropdown table, type_ID in the main table).

I've been working on this all day, so my mind is blown right now. Apologies in advance for any vital information I've missed in this posting.

    give the html option element a name attribute and then you can retrieve the value from the form post\get array.

      :queasy:

      Is this even close?

      <p>Type: <select type="type"><?php
      
        $sql = "SELECT DISTINCT type, ID FROM fd_type ORDER BY ID DESC";
        $result = mysql_query($sql);
        while ($row = mysql_fetch_assoc($result)) {
            ?>
            <option value="<?php echo "$row[ID]" ?>" <?php if ($row['type'] == ($_REQUEST['type'])) echo 'selected'; ?> name="$et"><?php echo $row['type'] ?></option><?php
        }
      ?>
      </select>
      <?php if (isset($_POST["$et"])) echo $_POST["$et"]; ?>
      *</p>

      It sounded so rational when you said it, but clearly it's beyond me at the mo. :o

      [Edit: $et is set earlier to equal the field type_ID in the main table, and that's a direct transliteration from the working $_POST statement. I tried a bunch of other name values which all failed equally spectacularly.]

        my mistake you need to name your select <select name="foo">

        then $_POST['foo'] will contain the selected value

          Like the fella in the other thread said, "dagon, you are a GOD!!" Thank you!! 😃

          I had to use the actual column name from the main table instead of a generic name in place of "foo", but once I had that in place it worked like a darn!

          😃

            Write a Reply...