NewSQLDev Posted April 11, 2013 Share Posted April 11, 2013 (edited) Hi all , im new on SQL and i have no idea why it doesnt work QUERY <!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)){ $con=mssql_connect("SERVER","USER","PASSWORD"); $ID=mssql_query("select UserUID from PS_UserData.dbo.Users where UserID='$user' "); $item=mssql_query("select ItemID from PS_GameData.dbo.UserItem where UserUID=$ID order by MakeTime"); $row=mssql_fetch_assoc($ID); echo $row["UserUID"]."<br>";} ?> </body> </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 April 11, 2013 by NewSQLDev Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/ Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 That code could not have caused that error. A. not only does it not contain the query that caused that, B. that code doesn't check for mssql errors. Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/#findComment-1424049 Share on other sites More sharing options...
mac_gyver Posted April 11, 2013 Share Posted April 11, 2013 the $ID variable contains a result resource from one query and inserting it into a string would result in something like Resource id #4 being put into the next query statement. Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/#findComment-1424053 Share on other sites More sharing options...
NewSQLDev Posted April 11, 2013 Author Share Posted April 11, 2013 not realy helpfull , thanks anyways i will try another forum Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/#findComment-1424168 Share on other sites More sharing options...
mac_gyver Posted April 11, 2013 Share Posted April 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/#findComment-1424178 Share on other sites More sharing options...
NewSQLDev Posted April 11, 2013 Author Share Posted April 11, 2013 i dont ask for a solution , read my topic , i ask to help me to a good direction. thanks anyways you can delete / close this topic Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/#findComment-1424218 Share on other sites More sharing options...
awjudd Posted April 12, 2013 Share Posted April 12, 2013 (edited) 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 April 12, 2013 by awjudd Quote Link to comment https://forums.phpfreaks.com/topic/276799-mssql-and-php-incorrect-syntax-near-id-severity-15/#findComment-1424336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.