rodife
rodife

Reputation: 25

Issue with Mysql_num_rows php/mysql

I'm trying to get email validation working. So my PHP code is firing off a query that that should return if it has any rows with the matching email. If 1 row is returned it then returns an error message, that I have else where in my code and sets my valid boolean to false.

However, I'm getting this error "Warning: mysql_num_rows() expects parameter 1 to be resource, object given in"

I think I'm using mysql_num_rows() wrong, but I'm new to php/mysql :( I can't seem to figure it out.

Here's the relevant sections of my code.

$conn = @mysqli_connect("server","user","pass","database");

if (!$conn) {
    // Displays an error message
    echo "<p>Database connection failure</p>";

////

        $sql_table="Customer";
        $query="SELECT * FROM $sql_table WHERE EMAIL = '$email'";
        $result = mysqli_query($conn, $query);

            if (mysql_num_rows($result) >= 1) { //<-- Offending line

                                $takenErr = "Email already taken ";
                                $valid = false; }

        if (!$result) {
            echo "<p> something is wrong with ", $query, "<p>";
            }

Thanks guys/gals! :).

Upvotes: 2

Views: 103

Answers (2)

Rakesh Shetty
Rakesh Shetty

Reputation: 4568

You are mixing mysqli_* and mysql_* function.

Try this :

if (mysqli_num_rows($result) > 0) { 

    $takenErr = "Email already taken ";
    $valid = false; 

}

For more information please read this mysqli_*

Upvotes: 0

tomexsans
tomexsans

Reputation: 4527

You can use

$row_cnt = $result->num_rows;

or

mysqli_num_rows($result);

you are using mysqli driver so use it at all times.

Upvotes: 1

Related Questions