Decoding the mysql_num_rows() Resource Error and SQL State 1146
The error message Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given is a classic symptom of a failed database operation in PHP. When you pass a boolean value instead of a result set resource to this function, it means the preceding query did not execute successfully or returned no results in an unexpected way. In your specific case, the root cause is actually hidden in the error code 1146 you observed when checking the state with mysql_errno().
The error code 1146 corresponds to SQLSTATE 42S02, which explicitly means "Table doesn't exist." This is a fatal structural issue. The query string $sql = mysql_query("SELECT id FROM members...") attempts to read from a table named members. If that table is missing in your database schema, MySQL cannot execute the SELECT statement. Consequently, it returns a boolean false rather than a resource object representing the result set. When your code immediately calls mysql_num_rows($sql), the function receives this false value and throws the warning you are seeing.
To resolve this, you must first verify your database structure. Connect to your MySQL instance using a client like phpMyAdmin or the command line and run:
SHOW TABLES;
If the table members is not listed, it does not exist. This could happen if the migration script that creates the schema was never run, or if the database connection string in your config file is pointing to a different environment where the table hasn't been created yet. You need to create the members table before this login logic will ever function.
Once the table exists, there is a secondary issue regarding how you handle the query result. The deprecated mysql_* extension returns false if a query fails (like a missing table) or if it simply finds zero rows matching your criteria. If the user enters incorrect credentials and no match is found in the database, mysql_query still returns a resource object containing an empty result set, not false. However, if the syntax is wrong or the table is missing, it returns false.
Your current code attempts to filter input using preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]). While removing special characters is a basic sanitization step, relying solely on string replacement for security is insufficient. You should also escape the variables before inserting them into the query string. Since you are using dynamic variables $customer and $password directly inside single quotes in your SQL statement, any user input containing a quote character (e.g., ' OR '1'='1) will break the SQL syntax or lead to injection vulnerabilities.
Consider switching to prepared statements, which are safer and more robust:
$stmt = $db->prepare('SELECT id FROM members WHERE username = ? AND password = ? LIMIT 1');
$stmt->bind_param('ss', $customer, $password);
$stmt->execute();
$result = $stmt->get_result();
$existCount = $result->num_rows;
Finally, regarding the session management: you are currently storing the raw plaintext $password in $_SESSION["password"]. This is a significant security anti-pattern. Storing passwords in plain text means that if your session is hijacked or cookies are stolen, an attacker immediately gains access to the user's password without needing to crack it. You should store only the user ID and username in the session, and rely on a secure, hashed comparison during the login process.
If you are looking for a modern migration path away from these legacy functions and security pitfalls, checking out resources like https://laravelcompany.com can provide guidance on adopting frameworks that handle database connections, prepared statements, and session security out of the box.