-1

The code:

  $stmt = mysqli_prepare($link, "SELECT * FROM adm_users WHERE users_username = ? AND users_password = ?");
  mysqli_stmt_bind_param($stmt, 'ss', $user_adm_name, $user_adm_password);
  mysqli_stmt_execute($stmt);
  mysqli_stmt_store_result($stmt);
  mysqli_stmt_fetch($stmt);
  $adm_check_log = mysqli_num_rows($stmt);
  mysqli_stmt_close($stmt);

Return:

Warning: mysqli_num_rows(): supplied argument is not a valid MySQL result

Why? Can someone explain for me?

Lion
  • 18,105
  • 22
  • 78
  • 106
John Jr
  • 1
  • 4

2 Answers2

0

You should check the return values of your functions!

(As a programmer do this in every situation when you encounter an error)

Seems that something is going wrong with the query. So change the code to something like:

$result = mysqli_query(...);

if(!$result) {
    die(mysqli_error($link);
}

Do the same with all of the mysqli functions that you are using.

hek2mgl
  • 143,113
  • 25
  • 227
  • 253
0

That simply means that the value for $stmt that is being passed in here:

$adm_check_log = mysqli_num_rows($stmt);

isn't of the correct type. Usually it indicates that you either didn't return anything from your query or there was an error with it.

Try outputting it to see what you get:

var_dump($stmt);

Replace what you have with this. What error is reported?

if($stmt = mysqli_prepare($link, "SELECT * FROM adm_users WHERE users_username = ? AND users_password = ?")) {
  $stmt->bind_param("ss", $user_adm_name, $user_adm_password);
  $stmt->execute();
  printf("Error: %d.\n", $stmt->error);
  $stmt->bind_result($foo);
  $stmt->fetch();
  var_dump($foo);
  $stmt->close();
}
rg88
  • 20,246
  • 18
  • 72
  • 109