title: Fatal Error due to PDO Exception because of a SQL query with dynamic PHP input
body: <p>After almost a day of researching I cannot really see what the error with my code is. I am trying to create a small prototype function that returns the number of rows of query results. </p>
  
  <p>The error I get is: <code>Uncaught PDOException: SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The multi-part identifier "my@email.com" could not be bound. in C:\inetpub\wwwroot\index.php:59</code></p>
  
  <p>Row 59 being <code>$stmt-&gt;execute();</code>.</p>
  
  <p>I believe the issue comes from my SQL query but I am not 100% sure.</p>
  
  <p>The way the code works is by getting values from a POST input and it checks in a row and column if it contains said value in a schema.</p>
  
  <p>Additionally, I am using MSSQL(not MySQLi) and PHP for the task. </p>
  
  <hr>
  
  <p>This is the main bit where I want the php code to send an SQL query and the check if the result exists.</p>
  
  <pre><code>&lt;?php  
      include "connect.php";
  
      if(isset($_POST['login']))
      {
          $email = $_POST['EMAIL'];
          $password = $_POST['PASSWORD']; 
  
          $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $stmt = $conn-&gt;prepare("SELECT * FROM users WHERE EMAIL=$email;"); 
          $stmt-&gt;execute();
  
          $count= $stmt-&gt;rowCount();
          echo "Row count: $count \n";
      }
  ?&gt; 
  </code></pre>
  
  <p>Just to mention I have tried all kinds of changes to the SQL query like:</p>
  
  <pre><code>$stmt = $conn-&gt;prepare("SELECT * FROM users WHERE EMAIL='".$email."';");
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$stmt = $conn-&gt;prepare("SELECT * FROM users WHERE EMAIL=?;");
  </code></pre>
  
  <p>with an array input that had <code>$email</code> in it.</p>
  
  <p><strong>All returned the same identical error.</strong></p>
  
  <hr>
  
  <p>Here I have the <code>connect.php</code>, just in case the issue might come from here.</p>
  
  <pre><code>&lt;?php 
          $servername = "localhost";
          $username = "sa";
          $password = ""; 
  
          try 
          {
              $conn = new PDO("sqlsrv:Server=$servername; Database=db", $username, $password);
              // set the PDO error mode to exception
              $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              echo "Connected!";
              return $conn;
          }
  
          catch(PDOException $e)
          {
              echo "Connection failed: " . $e-&gt;getMessage();
          }
  ?&gt;
  </code></pre>