0

I'm trying to pull number of rows seen in mysql database, but all I see is an error code. I have tried everything I know, I also checked PHP documentation but to no avail.

Code below

function signIn($email, $phone, $appName) {
        $conn = mysql_connect("localhost", "root", "");

        if ($conn) {
            $db = mysql_select_db("ahyoxsoft_registration");
        }
        if ($db) {
            $result_set = mysql_query("SELECT id FROM user_registration_info WHERE 
                email_address =". $email." AND phone_no =".$phone. " LIMIT 1");
                //echo ("No of rows :".mysql_num_rows($result_set));
            if ( (mysql_num_rows($result_set)) == 1 ) {
                $found = mysql_fetch_array($result_set);
                $_SESSION['user_id'] = $found['id'];
                header("Location: downloads/".$appName);    
            }//end if
        }
        mysql_close($conn);  
    }//end function signIn

Error

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\ahyoxsoft\includes\login.php on line 25

halfer
  • 19,471
  • 17
  • 87
  • 173
user3655892
  • 13
  • 1
  • 6

3 Answers3

1

when the result of mysql_query returns a boolean, this means you SQL query was incorrect; you forgot quotes:

$result_set = mysql_query("SELECT id FROM user_registration_info WHERE 
            email_address ='". $email."' AND phone_no ='".$phone. "' LIMIT 1");

But: while this may work, it is also susceptible for other errors and SQL injection. Read up on prepared statements and the PDO and MySQLi drivers. In fact, the mysql_* functions are deprecated.

Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185
0

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

Your sql query is executed with an error, so mysql_query returned false. check mysql_error ()

netdog
  • 91
  • 3
-2

You've got your code to run so that it will only fetch the array information if there is exactly 1 row. Change your code to the following:

            if ( (mysql_num_rows($result_set)) >= 1 ) {
                $found = mysql_fetch_array($result_set);
                $_SESSION['user_id'] = $found['id'];
                header("Location: downloads/".$appName);    
            }//end if
aashnisshah
  • 464
  • 4
  • 10