Feelay 0 Report post Posted February 1, 2008 Hey!I've made a register script.. Some time ago it worked. And I ain't sure if I changed something since then..The error I am getting is this:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31Here is the code on theese lines: $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'"; if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO user( username, password ) VALUES( '". $username ."', '". $password ."' )"; if( !mysql_query( $sqlRegUser ) ) { $feedback[] = 'You Could Not Register Because Of An Unexpected Error.'; } Any Idea What I've made wrong. And maybe anyone can tell me when mysql_num_rows errors occure. Thank You For You're Help//Feelay Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted February 8, 2008 Hey!I've made a register script.. Some time ago it worked. And I ain't sure if I changed something since then..The error I am getting is this:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31Here is the code on theese lines: $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'"; if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO user( username, password ) VALUES( '". $username ."', '". $password ."' )"; if( !mysql_query( $sqlRegUser ) ) { $feedback[] = 'You Could Not Register Because Of An Unexpected Error.'; } Any Idea What I've made wrong. And maybe anyone can tell me when mysql_num_rows errors occure. Thank You For You're Help//FeelayYou got that error because your query returns FALSE and the mysql_num_rows() function expects a valid result set, in this case it means that it is a new user and is valid to register, to work, try this code instead:<?php$sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";$result = mysql_query($sqlCheckForDuplicate) or die(mysql_error());if(mysql_num_rows($result)>0){ $feedback[] = 'You Could Not Register Because the User already exists.';}else{ $sqlRegUser = "INSERT INTO user(username, password) VALUES('$username','$password')"; if(!mysql_query($sqlRegUser)) { $feedback[] = 'You Could Not Register Because Of An Unexpected Error.'; }}?>Best regards, Share this post Link to post Share on other sites