title: get data from mysql with ajax and json into different textareas
body: <p>Ive just started to learn php a few weeks ago. I'm trying to do the same catalog program which i did in Access.
  But now im stuck. (i wrote a short copy of the program cos that is too long so this is similar as that)
  The problem is the next.
  I have an inputbox(ID) which would be an id number and some textareas(in this example 3 of them name-year-type) for the results. or it could be some other objects.
  When i enter the value the database gives me back the results from the fields where the id is the value i gave.
  Thats so far working with ajax but it gives to the 3 textareas the same results.
  What i would like to achieve is that all different field result be shown in different textareas. Ive tried with json but not really working. I will put up here the one with ajax (which is working good but the result should be seperated) and the one i tried with json. please if u have idea help me out. </p>
  
  <p><img src="https://i.stack.imgur.com/H7OfD.jpg" alt="my form"></p>
  
  <p>This one is working but does not separate the results:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;Get datas from database where (ID = value of input) and get back the datas into different textareas.&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  ID number:   &lt;input type="text" id="searchid" &gt;&lt;br&gt;
  
  Result Name: &lt;textarea id="resultname"&gt;&lt;/textarea&gt;&lt;br&gt;
  Result Year: &lt;textarea id="resultyear"&gt;&lt;/textarea&gt;&lt;br&gt;
  Result Type: &lt;textarea id="resulttype"&gt;&lt;/textarea&gt;&lt;br&gt;
  
  &lt;script&gt;
      $(document).ready(function() {
  
          $('#searchid').keydown(function (e){ // Event for enter keydown.
          if(e.keyCode == 13){
  
          var idvalue = $("#searchid").val(); // Input value.
  
              $.ajax({ //Ajax call.
  
                  type: "GET",
                  url: "search.php",
                  data: 'id=' + idvalue ,         
                  success: function(msg){
                      // Show results in textareas.
                      $('#resultname').html(msg.name);
                      $('#resultyear').html(msg.year);
                      $('#resulttype').html(msg.type);
                      }
  
                  }); // Ajax Call
              } //If statement
          }); //event handler
      }); //document.ready
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php
  
  if ($_GET['id']):   
      // Connect to database.
      $con = mysqli_connect("localhost","Krisz","password"); 
      mysqli_select_db ($con,'coin'); 
  
      // Get the values from the table.
      $sql = "SELECT Name, Year, Type FROM main_db where ID = $_GET[id] ";
      $result = mysqli_query($con,$sql);
  
      while($row = mysqli_fetch_assoc($result)) 
      {   
      echo "$row[Name]";  
      echo "$row[Year]";
      echo "$row[Type]";
      }
  
  endif;
  
  ?&gt;
  </code></pre>
  
  <p>Here i tried with json. im sure that there are a lot of mistakes.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;Get datas from database where (ID = value of input) and get back the datas into different textareas.&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
  
          $('#searchid').keydown(function (e){ // Event for enter keydown.
          if(e.keyCode == 13){
  
          var idvalue = $("#searchid").val(); // Input value.
  
              $.ajax({ //Ajax call.
  
                  type: "GET",
                  url: "search.php",
                  data: 'id=' + idvalue , 
                  type: 'json',
                  success: function(msg){
                      // Show results in textareas.
                      $('#resultname').html(msg.name);
                      $('#resultyear').html(msg.year);
                      $('#resulttype').html(msg.type);
                      }
  
                  }); // Ajax Call
              } //If statement
          }); //event handler
      }); //document.ready
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
      ID number:   &lt;input type="text" id="searchid" &gt;&lt;br&gt;
  
      Result Name: &lt;textarea id="resultname"&gt;&lt;/textarea&gt;&lt;br&gt;
      Result Year: &lt;textarea id="resultyear"&gt;&lt;/textarea&gt;&lt;br&gt;
      Result Type: &lt;textarea id="resulttype"&gt;&lt;/textarea&gt;&lt;br&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  
      &lt;?php
  if ($_GET['id']):   
  
      $dataid = json_decode($_GET['id']);
  
  
      // Connect to database.
      $con = mysqli_connect("localhost","Krisz","password"); 
      mysqli_select_db ($con,'coin'); 
  
      // Get the values from the table.
      $sql = "SELECT Name, Year, Type FROM main_db where ID = '$dataid' ";
      $result = mysqli_query($con,$sql);
  
      while($row = mysqli_fetch_assoc($result)) 
      {   
      $name = $row[Name]; 
      $type = $row[Type];
      $year = $row[Year];
      }
  
  $rows = array('name' =&gt; $name, 'type' =&gt; $type, 'year' =&gt; $year); 
  
  echo json_encode($rows);
  
  endif;
  
  ?&gt;
  </code></pre>
  
  <p>Im not sure if necessary to use json. Maybe there is other and simplier way to do it. </p>