0

I wish to update a record in MySql with PHP. Update is done with a standard HTML form including a drop down select populated from an Mysql query. Options are those already existing for that field in the data base

<?php
        
    $records = mysqli_query($conn, "SELECT DISTINCT `TDATE` FROM `MASTER_TABLE` WHERE `TDATE` <> 'TDATE' AND `TDATE` <> '' ");  
      echo "<option value=''>" ."" ."</option>"; // this just to give a blank entry field
     while($data = mysqli_fetch_array($records))
      
    {
        echo "<option value='". $data['TDATE'] ."'>" .$data['TDATE'] ."</option>";  // displaying data in option menu
    }   
?> 

That works fine of course - giving a blank field from the added option statement. ( I could take out the second part of the SQL query which would have the same effect) But I would like the user to be able to enter a new option into that blank field in the dropdown. But no approach seems quite to work tidely. ( That entered option will go into the database and appears in subsequent dropdown lists - thats already coded and working).

Thanks for answers so far . Seems to be still problems with some browsers on datalist. I got round it fornow by adding in another input field which takes priority but thats not very elegant.
I have no problem doing it within MSOffice apps just rather presumed there was a standard way of doing it

Steve U
  • 1
  • 3
  • 1
    Does this answer your question? [How can I create an editable dropdownlist in HTML?](https://stackoverflow.com/questions/264640/how-can-i-create-an-editable-dropdownlist-in-html) – Flash Ang Nov 18 '20 at 16:01
  • I was just about to suggest using an input + datalist (see the 2nd answer in @FlashAng 's link) – Pepper Nov 18 '20 at 16:03

0 Answers0