title: Echo or print a value from sql table using PHP PDO
body: <p><a href="https://i.stack.imgur.com/wI7Dq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wI7Dq.png" alt="enter image description here"></a></p>
  
  <p>I am trying to echo or print the last value of column <strong>usercode</strong> using PHP PDO. I tried to do this by using <strong>name</strong> column and SESSION var which will be the last values as references, but it doesn't work.</p>
  
  <pre><code>$name = $_SESSION['name'];
  
  $query = $db-&gt;prepare("SELECT usercode from users where name = $name ");
  $query-&gt;execute();
  
  $result = $query-&gt;setFetchMode(PDO::FETCH_ASSOC); 
  
  echo $result;
  </code></pre>