Show in textarea fields brought from mysql [duplicated]

0

Hi, I want to know how I can do that every time I select a select option it is added to a textarea, when I select an option it shows me this in textarea

  


Notice : Undefined index: id in C: \ xampp \ htdocs \ Login16 \ Login \ view \ edit.php on line 130

           <form>
   <?php 
    $query_mostrar_tema = "SELECT * FROM materiales"; 
                           $mostrar_tema = mysqli_query($conexion,$query_mostrar_tema ) or die(mysqli_error()); 
                           $row_mostrar_tema = mysqli_fetch_assoc($mostrar_tema); 
                           $totalRows_mostrar_tema = mysqli_num_rows($mostrar_tema); 
                            ?> 
                          <select id="tema" name="tema" onChange="actualizar()">> 
                          <?php do { ?> 
                          <option value="<?php echo $row_mostrar_tema['id']?>"><?php echo $row_mostrar_tema['nombre']?> 
                          </option> 
                          <?php 
                          } while ($row_mostrar_tema = mysqli_fetch_assoc($mostrar_tema));
                          $rows = mysqli_num_rows($tema); 
                          if($rows > 0) { 
                            mysqli_data_seek($tema, 0); 
                          $row_mostrar_tema = mysqli_fetch_assoc($tema); 
                            } 
                           ?> 
                               </select>
                               <script language="javascript">

                                var datos = [];

                               function actualizar() {

                              var select = document.querySelector('#tema').value;
                              var eltexto = document.querySelector('#eltexto');
                              datos.push(select);
                              eltexto.value = datos;
                              }
                             </Script>
                             <br>
                          <textarea id="eltexto" rows="10" cols="40"></textarea>
                            </form></div>
    
asked by Daniela 17.05.2018 в 19:17
source

2 answers

0

Let's see, the error of the undefined index is probably due to the fact that the field in the table materials is not exactly "id", possibly "ID" or "Id", php is very strict in relation to the associative arrays.

Regarding this code snippet:

$rows = mysqli_num_rows($tema); 
        if($rows > 0) { 
            mysqli_data_seek($tema, 0); 
            $row_mostrar_tema = mysqli_fetch_assoc($tema); 
        } 

The definition of the variable $ tema does not appear in the example you have contributed. I do not know if it will influence any subsequent error.

    
answered by 18.05.2018 / 12:35
source
0
function actualizar() {

    var select = document.querySelector('#tema').value
    var eltexto = document.querySelector('#eltexto');
    datos.push(select);
    eltexto.value =  datos.join("\n");;

}
    
answered by 17.05.2018 в 19:22