-1

编码:

  $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);

返回:

警告:mysqli_num_rows():提供的参数不是有效的 MySQL 结果

为什么?有人可以为我解释吗?

4

2 回答 2

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.

于 2013-03-05T22:43:38.873 回答
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();
}
于 2013-03-05T22:44:30.167 回答