You need to return the mysqli_result object first , with something like ...
$res = $stmt->get_result();
... then select the number of lines from this object (not $stmt ):
$numrows = mysqli_num_rows($res);
UPDATE: get_result is only available in PHP 5.3+; for older versions, use the following approach:
// $stmt preparing code goes here... $stmt->execute(); $stmt->store_result(); $num_rows = $stmt->num_rows; doSomethingWith($num_rows); // processing cycle: $stmt->bind_result($some_param, $another_param); while ($stmt->fetch()) { doSomethingElseWith($some_param, $another_param); } $stmt->free_result(); $stmt->close();
There are two recommendations as a side solution: 1) it is probably faster to use one query here and look for the value in both TeacherAlias ββand TeacherUsername fields at the same time (with the OR operator, for example TeacherAlias = ? OR TeacherUsername = ? ); 2) it would be easier to work with explicitly specified columns ( SELECT id, TeacherAlias AS alias, TeacherUsername AS username... ), and not just ( SELECT * ) in your query.
source share