title: Query SQL for username and return password
body: <p>I have a database of usernames and passwords. I need to create a "Forgot password" function and have it search the table for a username and return that user's password. Then I would like it to send an email saying the name and password. </p>
  
  <p>Here is my working code for querying the database for a specific user:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  include "config.php";
  
  if($_POST['nameQuery']) {
  
  $query = "SELECT * FROM myDatabase WHERE name = '" .$_POST['nameQuery']. "'";  
  $result = mysql_query($query);  
  if (mysql_num_rows($result) &gt; 0) { 
      //User exists
      echo '1'; 
  } else { 
      mysql_query($query);
  //User does not exist
  echo '0'; 
  }
  }
  ?&gt;
  </code></pre>