robcrozier Posted November 21, 2006 Share Posted November 21, 2006 Ok can anyone help me here. I've been working on this for ages and i just don't understand why this error keeps appearing with reference to the code below:[code]$query = "select username from customerwhere username = '$template_client_username'";$result = mysql_query($query); if (mysql_num_rows($result) == 0) {//username is free, break the loop as username is now setbreak;}else{ //loop again}[/code]This is the error that i keep getting, however bare in mind that it only appears when no valid match is found in the database resulting from the query. If there is a match found the error doesn't appear.[code]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\????????\????????\????????.php on line 164[/code]Thanks for taking a look! Quote Link to comment https://forums.phpfreaks.com/topic/27999-help-with-stupid-error-mysql_num_rows/ Share on other sites More sharing options...
.josh Posted November 21, 2006 Share Posted November 21, 2006 $result = mysql_query($query) or die(mysql_error() . " query: " . $query);post message. Quote Link to comment https://forums.phpfreaks.com/topic/27999-help-with-stupid-error-mysql_num_rows/#findComment-128077 Share on other sites More sharing options...
Psycho Posted November 21, 2006 Share Posted November 21, 2006 Are you properly connecting to the database? Are the table and column names correct?Plus you have no error handling on the query call itself.try this:[code]<?php$query = "select username from customerwhere username = '$template_client_username'";$result = mysql_query($query) OR die ("The query <br>".$query."<br>casued the following error<br>".mysql_error()); if (mysql_num_rows($result) == 0) {//username is free, break the loop as username is now setbreak;}else{ //loop again}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27999-help-with-stupid-error-mysql_num_rows/#findComment-128082 Share on other sites More sharing options...
robcrozier Posted November 21, 2006 Author Share Posted November 21, 2006 I've actually fixed it guys, used count() in query instead. Thanks for your help though!!! Quote Link to comment https://forums.phpfreaks.com/topic/27999-help-with-stupid-error-mysql_num_rows/#findComment-128087 Share on other sites More sharing options...
.josh Posted November 21, 2006 Share Posted November 21, 2006 that sounds more like a bandaid than a cure. oh well good luck. Quote Link to comment https://forums.phpfreaks.com/topic/27999-help-with-stupid-error-mysql_num_rows/#findComment-128088 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.