|
|
|
|
![]() ![]() |
Feb 1 2008, 06:17 PM
Post
#1
|
|
|
Kinda N00B Group: Members Posts: 219 Joined: 13-January 08 From: Sweden Member No.: 27,579 |
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 31 Here is the code on theese lines: CODE $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 |
|
|
|
Feb 8 2008, 02:10 AM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 750 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 |
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 31 Here is the code on theese lines: CODE $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 You 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: CODE <?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, |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 7th September 2008 - 11:14 AM |