title: sql query fails with variable
body: <p>I'm new to PHP and I'm sure I'm missing a basic detail. When I cast this query in SSMS it works fine. It also works if I type it exactly like this in PHP.</p>
  <p><a href="https://i.stack.imgur.com/2ujMJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ujMJ.png" alt="enter image description here" /></a></p>
  <p>But in my code, if I use the variable <code>$barcodevar</code> instead of a static value <code>'x'</code>. The query stops working.
  This is my code:</p>
  <pre><code>&lt;html&gt;
  &lt;input class=&quot;input&quot; type=&quot;text&quot; name=&quot;uid&quot;&gt;&lt;br&gt;
  &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;&gt;    
  &lt;?php                              
      if(isset($_POST['submit'])){
      }
          $barcodevar = $_POST['uid'];  
          $serverName = &quot;butterserver&quot;;
          $connectionInfo = array(&quot;Database&quot;=&gt;&quot;flowers&quot;, &quot;UID&quot;=&gt;&quot;buttercup&quot;, &quot;PWD&quot;=&gt;&quot;Admin123&quot;);
          $conn = sqlsrv_connect( $serverName, $connectionInfo);
          if($conn){
              if($barcodevar == &quot;&quot;){
                 echo &quot;field is empty&quot; ;    
              }
              $sql = &quot;SELECT SupplierLotID FROM FactsLot WHERE ID = $barcodevar&quot;;
              $stmt = sqlsrv_query( $conn, $sql);
              while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
                  echo $row['SupplierLotID'].&quot;&lt;br /&gt;&quot;;
              } 
              sqlsrv_free_stmt( $stmt );
              sqlsrv_close( $conn );
          }
          else{
              echo &quot;no connection&quot;;
          }                             
      ?&gt;
  &lt;/html
  </code></pre>
  <p>After echoing <code>$barcodevar</code> I can see that the value that I type in the &quot;uid&quot; is the same as used in the query of the picture.
  I can't find any errors so I don't know what the problem is. If there is any more information I should provide please ask, I hope we can solve this.</p>
  <p>thanks.</p>