我的mysqli_fetch_array()
代码有问题。我已经多次交换和更改变量以弄清楚为什么它不起作用。本质上,我需要它来访问我的数据库并找到符合特定条件的行数并返回值。关于我可以做些什么来让我的mysqli_fetch_array()
功能发挥作用的任何见解?
谢谢。
<html>
<?php
$uname = "";
$pword = "";
$errorMessage = "";
function quote_smart($handle, $value) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = "'" . mysqli_real_escape_string($handle, $value) . "'";
}
return $value;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$uname = $_POST['username'];
$pword = $_POST['password'];
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
$con = mysqli_connect("127.0.0.1", "root", "");
$db = mysqli_select_db($con, "users");
if ($db) {
$uname = quote_smart($con, $uname);
$pword = quote_smart($con, $pword);
$SQL = "SELECT * FROM users WHERE L1 = $uname AND L2 = md5($pword)";
$result = mysqli_query($con, $SQL);
$num_rows = mysqli_fetch_array($result,MYSQLI_NUM);
if ($result) {
if ($num_rows > 0) {
session_start();
$_SESSION['login'] = "1";
header ("Location: home.php");
}
else {
session_start();
$_SESSION['login'] = "";
header ("Location: regpage.php");
}
}
else {
$errorMessage = "Error logging on";
}
mysqli_close($con);
}
else {
$errorMessage = "Error logging on";
}
}
?>
</html>
我遇到的主要代码是:
$num_rows = mysqli_fetch_array($result,MYSQLI_NUM);
每次运行它时,我都会收到以下错误消息:
警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,布尔值