gpt4 book ai didi

php - 查询在本地机器上工作正常,但在服务器上失败

转载 作者:行者123 更新时间:2023-11-29 22:23:38 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

(31 个回答)


6年前关闭。




我有一个在我的计算机上运行良好的登录系统,但是在使用服务器上的 HTML 用户界面登录时,查询似乎不起作用。我已经复制并直接在服务器上运行查询并且工作正常。我得到的错误是:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given



代码如下:
<?php
include_once 'header.php';

$error = "";
$userID = "";
$username = "";

$userName = isset($_POST["userName"]) ? sanitizeString($_POST["userName"]) : "";
$pass = isset($_POST["pass"]) ? sanitizeString($_POST["pass"]) : "";


if (isset($_POST["login"]))
{
if (empty($userName) || empty($pass))
$error = "<span class='error'>Not all fields were entered</span><br />";
else
{
$login_query = "SELECT
*
FROM users
WHERE username = ?
AND pass = ?";
$login_result = queryMysqli($login_query,array(
array("s",$userName),
array("s",md5($salt.$pass.$pepper)))
);

if (mysqli_num_rows($login_result) == 0)
$error = "<span class='error'>Username/Password invalid</span>";
else
{
$row = mysqli_fetch_array($login_result);
$userID = $row["ID"];
$username = $row["username"];

//Add to session
$_SESSION['userID'] = $userID;
$_SESSION['username'] = $userName;

header("location:manageAdverts.php");
EXIT;
}
}
}
?>

<div class="container">
<div class="col-sm-10">
<div class="row">
<div id="main_body">
<div style="padding:55px;">
<div class="white_background " style="max-width:450px;margin-top:40px;">
<span style="color:red;"><?php echo $error; ?></span>
<p style="font-family: 'Oswald', sans-serif;font-size:26px;margin-bottom:20px;">Login</p>
<div style="border-right:1px solid blue;float:left;">
<form class="form-horizontal" method="post" >
<div class="form-group">
<div class="col-xs-10">
<input type="text" class="form-control" placeholder="Username" name="userName" autofocus value="<?php echo $userName; ?>">
</div>
</div>
<div class="form-group">
<div class="col-xs-10">
<input type="password" class="form-control" placeholder="Password" name="pass" value="<?php echo $pass; ?>">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<p></p>
<button style="background:#0B0B61;" type="submit" class="btn btn-primary" name="login">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include_once "footer.php"; ?>

最佳答案

尝试更改此行

if (mysqli_num_rows($login_result) == 0)


if (mysqli_num_rows($login_result) === FALSE)

并告诉我它是否解决了错误!

关于php - 查询在本地机器上工作正常,但在服务器上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30475209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com