Jump to content

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


NewSQLDev
 Share

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

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

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

 Share

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