Jump to content

MSSQL and PHP Incorrect syntax near 'id'. (severity 15


NewSQLDev

Recommended Posts

Hi all ,
 
im new on SQL and i have no idea why it doesnt work
 
 
 
QUERY

 

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  5. User<input type="text" name="user">
  6. <input type="submit">
  7. </form>
  8. <?php
  9.  
  10. $user=$_POST['user'];
  11. if(isset($user)){
  12. $con=mssql_connect("SERVER","USER","PASSWORD");
  13. $ID=mssql_query("select UserUID from PS_UserData.dbo.Users where UserID='$user' ");
  14. $item=mssql_query("select ItemID from PS_GameData.dbo.UserItem where UserUID=$ID order by MakeTime");
  15. $row=mssql_fetch_assoc($ID);
  16. echo $row["UserUID"]."<br>";}
  17. ?>
  18. </body>
  19. </html>

 


 
 
ERROR

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'id'. (severity 15) in C:\xampp\htdocs\index.php on line 14

 

Normaly $ID(without '' cause its a int data) should give as result "2" (without "" , its INT data )
so $item can find the UserUID from that database
but i got a error "Incorrect syntax near 'id'. (severity 15"

 

could u plz tell me what i do wrong and help me in the correct way :)

 

 

Thanks advanced

Link to post
Share on other sites

sticking with a problem until it is solved is actually a highly valued trait, no matter what the subject is.

 

if you just post your code and your error on any help forum and expect a copy/paste solution that won't involve any effort on your part, you are in for a huge surprise.

Link to post
Share on other sites

As mac_gyver said, you need to change $ID.  Right now it is the result from a query, you will need to first grab the row.  Or you can change your second query to join against the User table.

<!DOCTYPE html>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
User<input type="text" name="user">
<input type="submit">
</form>
<?php
 
$user=$_POST['user'];
if(isset($user)){

// You need some SQL injection protection here
$con=mssql_connect("SERVER","USER","PASSWORD");
$item=mssql_query("select ItemID from PS_GameData.dbo.UserItem AS ui JOIN PS_UserData.dbo.Users AS u ON ui.UserUID = u.UserUID where UserID = '$user' order by MakeTime");
}
?>
</body>
</html>
Link to post
Share on other sites

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.