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.
But in my code, if I use the variable $barcodevar
instead of a static value 'x'
. The query stops working.
This is my code:
<html>
<input class="input" type="text" name="uid"><br>
<input type="submit" name="submit" value="Submit">
<?php
if(isset($_POST['submit'])){
}
$barcodevar = $_POST['uid'];
$serverName = "butterserver";
$connectionInfo = array("Database"=>"flowers", "UID"=>"buttercup", "PWD"=>"Admin123");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn){
if($barcodevar == ""){
echo "field is empty" ;
}
$sql = "SELECT SupplierLotID FROM FactsLot WHERE ID = $barcodevar";
$stmt = sqlsrv_query( $conn, $sql);
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo $row['SupplierLotID']."<br />";
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
}
else{
echo "no connection";
}
?>
</html
After echoing $barcodevar
I can see that the value that I type in the "uid" 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.
thanks.