title: How to get MySQL select query values into a PHP variable?
body: <p>I know I need to use the MySQL fetch to prevent getting a resource ID in my variable but I wondered if you could help me out how to do that. I see from several tutorials they use a loop but I just want to select the one string into a variable. Here is the code I have:</p>
  
  <pre><code>$img = mysql_query('SELECT pname FROM photos WHERE pphotoid=21');
  echo $img;
  </code></pre>
  
  <p>I basically want <code>$img</code> to contain the string in the database not <code>Resource id #3</code> it is currently showing. Also is what I wrote prone to an SQL injection?</p>
  
  <p>Learning MySQL so any help would be great!</p>