Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 NewSQLDev

NewSQLDev

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 10 April 2013 - 08:36 PM

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, 10 April 2013 - 08:38 PM.


#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 10 April 2013 - 08:38 PM

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.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 mac_gyver

mac_gyver

    Advanced Member

  • Moderators
  • 1,896 posts

Posted 10 April 2013 - 08:57 PM

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.


multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]

#4 NewSQLDev

NewSQLDev

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 April 2013 - 11:48 AM

not realy helpfull , thanks anyways i will try another forum 



#5 mac_gyver

mac_gyver

    Advanced Member

  • Moderators
  • 1,896 posts

Posted 11 April 2013 - 12:09 PM

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.


multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]

#6 NewSQLDev

NewSQLDev

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 April 2013 - 03:24 PM

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 



#7 awjudd

awjudd

    Advanced Member

  • Gurus
  • 424 posts

Posted 12 April 2013 - 05:46 AM

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, 12 April 2013 - 05:47 AM.

The law of everything: Garbage in, Garbage out.

If you don't give us enough information to help you the correct way, the results won't end up being correct.

Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com