title: Get variables from JSON variable
body: <p>Im having some problems getting different variables from a JSON variable.</p>
  
  <p>I do a $.post on get_shop.php file that gets data from a database, take the results and put it into a array and do a json_encode on it and prints it.</p>
  
  <p>get_shop.php:</p>
  
  <pre><code>$id = $_GET["id"];
  
      $query = " 
          SELECT 
              *
          FROM shop
          WHERE 
              id = :id
      "; 
  
      // The parameter values 
      $query_params = array( 
          ':id' =&gt; $id
      ); 
  
      try 
      { 
          // Execute the query against the database 
          $stmt = $db-&gt;prepare($query); 
          $result = $stmt-&gt;execute($query_params); 
      } 
      catch(PDOException $ex) 
      { 
          // Note: On a production website, you should not output $ex-&gt;getMessage(). 
          // It may provide an attacker with helpful information about your code.  
          die("Failed to run query: " . $ex-&gt;getMessage()); 
      } 
  
      // Retrieve the user data from the database.  If $row is false, then the username 
      // they entered is not registered. 
      $row = $stmt-&gt;fetch(); 
  
      $database_data = array(
      "name" =&gt; $row["name"],
      "description" =&gt; $row["description"],
      "category" =&gt; $row["category"],
      "price" =&gt; $row["price"]
      );
  
      print(json_encode($database_data, JSON_UNESCAPED_UNICODE));
  </code></pre>
  
  <p>After that i do a console.log with the data received in shop.php (The file that makes the $.post request)</p>
  
  <p>shop.php $.post sample:</p>
  
  <pre><code>$(document).ready(function(){
  console.log("ID: " + id );
  
  $.post("get_shop.php?id="+id+"",
  function(data,status){
  
  console.log(data + "\nStatus: " + status); )};
  </code></pre>
  
  <p>An example for a result: </p>
  
  <pre><code>{"name":"Hardrive 5GB","description":"Speed 10MB/s","category":"Hardrive","price":"1000"}
  </code></pre>
  
  <p>Now, the problem is that i want to show a part of the result (Like just "name") but it says "undefined" (I use data[name]). How do i solve this? Thanks!</p>