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? Link to comment https://forums.phpfreaks.com/topic/90671-username-field-column-in-table-is-it-reserved/ 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'"); Link to comment https://forums.phpfreaks.com/topic/90671-username-field-column-in-table-is-it-reserved/#findComment-464765 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 Link to comment https://forums.phpfreaks.com/topic/90671-username-field-column-in-table-is-it-reserved/#findComment-464840 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! Link to comment https://forums.phpfreaks.com/topic/90671-username-field-column-in-table-is-it-reserved/#findComment-464920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.