Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Warning: Mysql_num_rows(), What is the error :S
Feelay
post Feb 1 2008, 06:17 PM
Post #1


Kinda N00B
Group Icon

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
Go to the top of the page
 
+Quote Post
TavoxPeru
post Feb 8 2008, 02:10 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 750
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(Feelay @ Feb 1 2008, 01:17 PM) *
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,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL & PHP coding(9)
  2. Need Help With A PHP - MySQL Registration Script(13)
  3. [PHP + MySQL] Encrypting Data(9)
  4. How Do You Create A Secure Loging?(4)
  5. Important: Basics Of Using PHP And MySQL(9)
  6. Need Help With Php/mysql And Web Servers Such As Asta's.(4)
  7. E-mail List Error(4)
  8. Got A Wee Error - Can You Help?(13)
  9. Need MySQL Alternative To The Syntax "or die()"(8)
  10. Re-order MySQL Table(11)
  11. PHP & MySQL: Displaying Content From A Given ID(6)
  12. How To Show Serial Nums In PHP Table For Contents Of MySQL DB(4)
  13. Error On Submit Page(10)
  14. Php Mysql Errors(2)
  15. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  1. Php/mysql And Manual Page Caching?(4)
  2. Too Many Connections?(4)
  3. Extracting Mysql Maths Using Php(2)
  4. Unexpected Error(2)
  5. Php Math Error(4)
  6. Anyone Know Of A Really Good Mysql Class?(4)
  7. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  8. Php Error-where To Put "?>"(2)
  9. Making A Link = Mysql_query(8)
  10. Making Something In Mysql Happen Only Once(10)
  11. Mysql Question(inserting Number From A Textfield)(3)
  12. Letting Users Add Mysql Data With Php(1)
  13. Cant Find The Error(2)


 



- Lo-Fi Version Time is now: 7th September 2008 - 11:14 AM