Mavent Posted March 7, 2012 Share Posted March 7, 2012 This works: $result = mysql_query("SELECT * FROM mydatabase WHERE username = 'billybob'"); This does not: $user = "billybob" $result = mysql_query("SELECT * FROM mydatabase WHERE username = $user"); Shouldn't these be identical? If I echo $user, I get, of course, "billybob", so does anyone know why the variable isn't working in the query itself? Link to comment https://forums.phpfreaks.com/topic/258422-post-variables-in-mysql_query-failing/ Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2012 Share Posted March 7, 2012 String values need to be enclosed in quotes in the query string. Link to comment https://forums.phpfreaks.com/topic/258422-post-variables-in-mysql_query-failing/#findComment-1324684 Share on other sites More sharing options...
Mavent Posted March 7, 2012 Author Share Posted March 7, 2012 String values need to be enclosed in quotes in the query string. I could have SWORN that I tried it that way initially, but obviously I didn't, because the second I changed it to '$user' it worked perfectly. Thanks Pikachu2000! Link to comment https://forums.phpfreaks.com/topic/258422-post-variables-in-mysql_query-failing/#findComment-1324686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.