title: How to use a PHP variable in Inner Join MYSQL query?
body: <p>I have been trying for the past day to get mysql to recognize my PhP variable, but I have had no luck so far. </p>
  
  <p>The code:</p>
  
  <pre><code>...connect to db...
  session_start();
  //Calls up Session stored variable
  $currentUsr= $_SESSION['username'];
  //SQL Query
  $sql= 'SELECT Users.Username, books.* FROM Users
         INNER JOIN UserLinkBooks lb
         ON Users.Username = lb.Username
         INNER JOIN Books
         ON lb.bkTitle = books.Title
         WHERE Users.Username = "$currentUsr"';
  $result=mysqli_query($conn,$sql);                                                                
  //Error Check
  if (!$result) {                                                                                   
     printf("Error: %s\n", mysqli_error($conn)); 
     exit();}
  //display row
  while($row=mysqli_fetch_array($result)){                                                                                                        
      echo "&lt;strong&gt;".$row['Title']."&lt;/strong&gt;".$row['Description']."&lt;/br&gt;";}   
  </code></pre>
  
  <p>My issue is that the $currentUsr is not properly calling the username that was passed. After doing an error check on it, it seems to be empty.</p>
  
  <p>What I do not understand is that when I use the code :</p>
  
  <pre><code>$sql = "SELECT * FROM Users WHERE `Username`='$currentUsr'";
  </code></pre>
  
  <p>The variable is processed and works fine, calling up the book title's and description perfectly. Also, if I manually type in:
        WHERE Users.UserName = "Bill"';
  It works fine.</p>
  
  <p>Some of the other errors I've gotten from various attempts are: </p>
  
  <pre><code>  WHERE Users.UserName = '.'$currentUsr';
    Error: Unknown column '$currentUsr' in 'where clause'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>  WHERE Users.UserName = '.$currentUsr;  
    Error:  Unknown column 'Bill' in 'where clause'
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thanks</p>