title: Get the database content posted on a selected option into a form with single fields
body: <p>I have a form with a select. The options are coming from a database and displayed into the select.</p>
  
  <p>The columns on the database are:</p>
  
  <pre><code>id, date, title, body.
  </code></pre>
  
  <p>On the select I display only date and title. In the same page I have a form with:</p>
  
  <pre><code> date -&gt; input text
   title -&gt; input text
   body -&gt; text area
  </code></pre>
  
  <p>I want that when an option from the select is clicked by the user the fields below will be update with the content kept from the selected option which contain the database data.</p>
  
  <p>Now I have no idea how to get the data on the fields below.
  My idea was to get the index of the option of the drop down. Is this possible?</p>
  
  <p>EDIT COMPLETE CODE:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;div class="normal"&gt;
  &lt;table style="width:100%;height:100%;" border="1"&gt;
      &lt;tr&gt;
          &lt;td width="174"&gt;&lt;strong&gt;geste n&lt;/strong&gt;&lt;/td&gt;
  
          &lt;td width="505" valign="middle" height="24"&gt;
  
              &lt;input type="radio" name="n" id="new" value="nuova" onchange="shown(this.id);" &lt;?php if($_POST['n'] == "nuova"){echo "CHECKED";} ?&gt; /&gt;Nuova n
              &lt;input type="radio" name="n" id="mod" value="modifica" onchange="shown(this.id);" &lt;?php if($_POST['n'] == "modifica"){echo "CHECKED";} ?&gt; /&gt;Modifica n
                  &lt;select id="sceltannascosta" style="display:none"&gt;
                      &lt;?php
                          include("/login/flock/sql.php");
                          $conn = mysqli_connect($host, $user, $pw, $db) or die("Impossibile connettersi"); 
                          $a = "SELECT * FROM n ORDER BY id DESC";
                          $b = mysqli_query($conn, $a);                       
                              print '&lt;option&gt;&lt;/option&gt;';                      
                          while ($c = $b-&gt;fetch_object()) {
                              print '&lt;option&gt;'.$c-&gt;id.$c-&gt;data.$c-&gt;title.$c-&gt;body.'&lt;/option&gt;';
                          }
                          $b-&gt;close();
                          $conn-&gt;close;      
                      ?&gt;    
                  &lt;/select&gt;
  
                  &lt;select id="sceltan" style="display:none" onChange="showEntry(this,this.value);setndamod(this);"&gt;
                      &lt;?php
                          include("/login/flock/sql.php");
                          $conn = mysqli_connect($host, $user, $pw, $db) or die("Impossibile connettersi"); 
                          $a = "SELECT * FROM n ORDER BY id DESC";
                          $b = mysqli_query($conn, $a);                       
                              print '&lt;option&gt;&lt;/option&gt;';                      
                          while ($c = $b-&gt;fetch_object()) {
                              print '&lt;option&gt;'.$c-&gt;data.' - '.$c-&gt;title.'&lt;/option&gt;';
                          }
                          $b-&gt;close();
                          $conn-&gt;close;      
                      ?&gt;  
                  &lt;/select&gt;                
              &lt;input type="submit" id="botenascostogeste" class="button"&gt;       
          &lt;/form&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  
  &lt;div class="normal" id="c" style="display:none"&gt;
  &lt;table style="width:100%;height:100%;"&gt;
    &lt;tr&gt;
        &lt;td colspan="3" border="0"&gt;
          &lt;strong class="confirm"&gt;c nuova n&lt;/strong&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td width="107" align="right"&gt;
          &lt;strong&gt;Data&lt;/strong&gt;
      &lt;/td&gt;
      &lt;td colspan="2"&gt;
          &lt;form name="nuovan" method="post" action="cht.php?c=yes"&gt;
              &lt;input name="datan" type="text" maxlength="10" size="8" value="&lt;?php echo date(d.".".m.".".Y) ?&gt;"&gt; gg.mm.aaaa
      &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
        &lt;td align="right"&gt;
          &lt;strong&gt;Titolo&lt;/strong&gt;
        &lt;td width="360"&gt;
                  &lt;input name="titolon" type="text" maxlength="50" size="50" value="&lt;? echo htmlspecialchars("titolo n - lunghezza massima 50 caratteri") ?&gt;" onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')"&gt;
        &lt;/td&gt;
        &lt;td width="522"&gt;
            &lt;b&gt;&lt;span id=myCounter&gt;6&lt;/span&gt;&lt;/b&gt; caratteri rimanenti per il titolo&lt;/font&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td colspan="3"&gt;
                  &lt;textarea name="teston"&gt;&lt;?php if(isset($_POST['teston'])){echo $_POST['teston'];}else{echo 'Testo n con stile personalizzato';} ?&gt;&lt;/textarea&gt;
                  &lt;script&gt;
                      CKEDITOR.replace('teston');
                  &lt;/script&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td align="right"&gt;
          &lt;input type="submit" name="c" class="button" onClick="document.getElementById('botenascostogeste').click();"&gt;
      &lt;/form&gt;
      &lt;/td&gt;
      &lt;td colspan="2"&gt;
      &lt;?php
          $c = $_GET['c'];                
          $titolon = $_POST['titolon'];
          $teston = $_POST['teston'];
          $datascritta = $_POST['datan'];
  
          if($c == 'yes'){                        
              if($_POST['titolon'] == NULL || $_POST['teston'] == NULL || $_POST['datan'] == NULL){
                  echo '&lt;img src="'.$imagen.'" style=width:"' . $width . 'px;height:' . $height . 'px;"&gt;';
              } else {
  
                  function verificadata($datascritta) { 
                      list($dd,$mm,$yyyy)=explode(".",$datascritta); 
                      if (is_numeric($dd) &amp;&amp; is_numeric($mm) &amp;&amp; is_numeric($yyyy)) 
                      { 
                          return checkdate($mm,$dd,$yyyy); 
                      } 
                      return false;            
                  }
  
                  if(verificadata($datascritta)){
                      $connessione = mysql_connect ($host, $user, $pw) or     //connect to the database 
                          die('&lt;img src="'.$imagen.'" style=width:"' . $width . 'px;height:' . $height . 'px;"&gt;');                                                    
                      mysql_select_db ($db); //select the database                
                      mysql_query("INSERT INTO n(data, title, body) VALUES ('$datascritta', '$titolon', '$teston')");
                      mysql_close($connessione);
                      echo ('&lt;img src="'.$imagey.'" style=width:"' . $width . 'px;height:' . $height . 'px;"&gt; Ok'); // It worked.
                  } else { die('&lt;img src="'.$imagen.'" style=width:"' . $width . 'px;height:' . $height . 'px;"&gt;');                                                   
                  }
              }
          }
      ?&gt;    
      &lt;/td&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  
  &lt;div class="normal" id="modifica" style="display:none"&gt;
  &lt;table style="width:100%;height:100%;"&gt;
    &lt;tr&gt;
        &lt;td colspan="3" border="0"&gt;
          &lt;strong class="confirm"&gt;Modifica n&lt;/strong&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td width="107" align="right"&gt;
          &lt;strong&gt;Data&lt;/strong&gt;
      &lt;/td&gt;
      &lt;td colspan="2"&gt;
          &lt;form name="modifican" method="post" action="cht.php?modifica=yes"&gt;
              &lt;input name="idmodifican" type="text" style="display:none" value="INSERIRE ID DI MODIFICA DEL DATABASE QUI"&gt;
              &lt;input name="datanmodificata" type="text" maxlength="10" size="8" value="POST DATE FROM THE n TO MODIFY SELECTED"&gt; gg.mm.aaaa
      &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
        &lt;td align="right"&gt;
          &lt;strong&gt;Titolo&lt;/strong&gt;
        &lt;/td&gt;
        &lt;td width="360"&gt;
                  &lt;input name="modificatitolo" type="text" maxlength="50" size="50" value="POST TITLE FROM THE n TO MODIFY SELECTED" onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')"&gt;
        &lt;/td&gt;
        &lt;td width="522"&gt;
            &lt;b&gt;&lt;span id=myCounter&gt;50&lt;/span&gt;&lt;/b&gt; caratteri rimanenti per il titolo&lt;/font&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td colspan="3"&gt;
                  &lt;textarea name="modificatesto"&gt;POST BODY FROM THE n TO MODIFY SELECTED&lt;/textarea&gt;
                  &lt;script&gt;
                      CKEDITOR.replace('modificatesto');
                  &lt;/script&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td align="right"&gt;
          &lt;input type="submit" name="modifica" class="button"&gt;
      &lt;/form&gt;
      &lt;/td&gt;
      &lt;td colspan="2"&gt;
      PHP I HAVE TO DO TO UPDATE THE n ON THE DATABASE (I'm able to do this part).
      &lt;/td&gt;
  &lt;/table&gt;
  &lt;/div&gt;  
  
  &lt;/body&gt;
  </code></pre>