Jump to content

PHP + MSSQL Incorrect syntax near the keyword 'User'. Error


impactfactor

Recommended Posts

The following is the error I am receiving:

Warning: mssql_query(): message: Incorrect syntax near the keyword 'User'. (severity 15) in /var/www/try.php on line 25

 

I understand User is a protected keyword in SQL Server but how can I get past this? Do I have to surround the word user in specific characters? My code is below:

 

<?php
ini_set('display_errors', 1); 
ini_set('log_errors', 1); 
ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); 
error_reporting(E_ALL);
$con = mssql_connect('172.21.30.19', 'sa', 'nsn4hill');
if (!$con)
{
die('Could not connect: ' . mssql_error());
}

mssql_select_db("Intranet", $con);

$sql="SELECT CAST UserID AS TEXT FROM User";

$result = mssql_query($sql);

echo "<table border='1'>
<tr>
<COL width='100'>
<th bgcolor='black' style ='color:white'>Patch ID</th>
</tr>";

while($row = mssql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['UserID'] . "</td>";
echo "</tr>";
}
echo "</table>";

mssql_close($con);
?>

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.