Jump to content

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


Recommended Posts

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


  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
  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>



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

Edited by NewSQLDev
Link to comment
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 comment
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>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
User<input type="text" name="user">
<input type="submit">

// You need some SQL injection protection here
$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");
Edited by awjudd
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 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.