2

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! :).

1
  • 2
    There is exists two different extensions mysqli_* and mysql_. You are trying to mix it. Commented Sep 12, 2014 at 4:54

2 Answers 2

1

You can use

$row_cnt = $result->num_rows;

or

mysqli_num_rows($result);

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

Sign up to request clarification or add additional context in comments.

2 Comments

Adding the mysqli fixed it :).
thats great, glad it helps :D
0

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_*

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.