Siggles Posted February 12, 2008 Share Posted February 12, 2008 I am trying to run a simple select statement. $result = mysql_query("SELECT * FROM `users` WHERE `username` = $usertoedit "); The error I get is Unknown column 'Roger' in 'where clause' for example. Why is this. I know one question asked will be does username column actually exist but I am certain it does. Please help. Is there a way around this? Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2008 Share Posted February 12, 2008 Try... $result = mysql_query("SELECT * FROM `users` WHERE `username` = '$usertoedit'"); Quote Link to comment Share on other sites More sharing options...
beebum Posted February 12, 2008 Share Posted February 12, 2008 FYI, for a complete list of reserved words see: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment Share on other sites More sharing options...
aschk Posted February 12, 2008 Share Posted February 12, 2008 To give you some clarity on what went wrong. Say you set $usertoedit = "Roger"; Then if you echo'd out your query you should get the following: SELECT * FROM `users` WHERE `username` = Roger MySQL assumes (because you haven't used single quotes (') ) that you're asking if the column username equals the column Roger. So in summation: MAKE SURE YOU QUOTE YOUR STRINGS! Quote Link to comment 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.