weemikey Posted July 19, 2007 Share Posted July 19, 2007 Thanks in advance for any help! I have this little query to look for any records that ALREADY use the entered screen name. Here's my query (built in php): $name_sql = "SELECT member.screen_name, member.public_email FROM member WHERE member.screen_name = ".$screen_name; //mysql_query returns true for success or false for error $result = mysql_query($name_sql,dbconnect()) or die(mysql_error($mysql)); If the user had entered "weemikey" as a screen name, for example, the error I would get is 'Unknown column 'weemikey' in 'where clause'. So I take it mysql thinks the value of my variable $screen_name is a column in the database? I am using all kinds of queries that look just like this and I do NOT understand why it's doing this. Any ideas that are so obvious I would have walked right by? Quote Link to comment https://forums.phpfreaks.com/topic/60700-solved-i-dont-understand-whats-wrong-with-this-query/ Share on other sites More sharing options...
keeB Posted July 19, 2007 Share Posted July 19, 2007 Single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/60700-solved-i-dont-understand-whats-wrong-with-this-query/#findComment-302022 Share on other sites More sharing options...
Rashy Posted July 19, 2007 Share Posted July 19, 2007 $name_sql = "SELECT member.screen_name, member.public_email FROM member WHERE member.screen_name = '$screen_name'"; I think that should work $name_sql = "SELECT member.screen_name, member.public_email FROM member WHERE member.screen_name = '" . $screen_name . "'"; Try that if the first doesn't. I think they should both work though. Quote Link to comment https://forums.phpfreaks.com/topic/60700-solved-i-dont-understand-whats-wrong-with-this-query/#findComment-302080 Share on other sites More sharing options...
DeadEvil Posted July 19, 2007 Share Posted July 19, 2007 $name_sql = "SELECT member.screen_name, member.public_email FROM member WHERE member.screen_name = '$screen_name'"; $result = mysql_query($name_sql,dbconnect()) or die(mysql_error($mysql)); Quote Link to comment https://forums.phpfreaks.com/topic/60700-solved-i-dont-understand-whats-wrong-with-this-query/#findComment-302088 Share on other sites More sharing options...
Barand Posted July 19, 2007 Share Posted July 19, 2007 You don't want to connect for every query or your scripts will take forever (unless you are connecting to different servers each time) Connect once then just use "mysql_query($name_sql)" Quote Link to comment https://forums.phpfreaks.com/topic/60700-solved-i-dont-understand-whats-wrong-with-this-query/#findComment-302670 Share on other sites More sharing options...
weemikey Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks everyone. I get VERY confused with the single and double quotes when building a string of html or sql in php with all the potential for escape characters that I don't know about! Quote Link to comment https://forums.phpfreaks.com/topic/60700-solved-i-dont-understand-whats-wrong-with-this-query/#findComment-302736 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.