LooieENG Posted September 5, 2008 Share Posted September 5, 2008 $result = mysql_query("SELECT $username FROM users"); $queries++; if (mysql_num_rows($result) == 0) { Gives Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /xxx/xxx/ on line 11 Link to comment https://forums.phpfreaks.com/topic/122933-solved-how-to-fix-this-mysql-query/ Share on other sites More sharing options...
Ken2k7 Posted September 5, 2008 Share Posted September 5, 2008 Is $username the name of a column? That's really strange. SELECT * FROM `users` WHERE `username` = '$username' Link to comment https://forums.phpfreaks.com/topic/122933-solved-how-to-fix-this-mysql-query/#findComment-634914 Share on other sites More sharing options...
LooieENG Posted September 5, 2008 Author Share Posted September 5, 2008 Ah, woops. I have the column "username" and I wanted to search for $username Do I need to use * because I only want to check if the username exists? Link to comment https://forums.phpfreaks.com/topic/122933-solved-how-to-fix-this-mysql-query/#findComment-634916 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 It doesn't matter. Link to comment https://forums.phpfreaks.com/topic/122933-solved-how-to-fix-this-mysql-query/#findComment-634918 Share on other sites More sharing options...
Ken2k7 Posted September 5, 2008 Share Posted September 5, 2008 function username_exists ($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username' LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); return mysql_num_rows($result) == 1; } Link to comment https://forums.phpfreaks.com/topic/122933-solved-how-to-fix-this-mysql-query/#findComment-634919 Share on other sites More sharing options...
LooieENG Posted September 5, 2008 Author Share Posted September 5, 2008 Thanks for the help Link to comment https://forums.phpfreaks.com/topic/122933-solved-how-to-fix-this-mysql-query/#findComment-634922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.