gpt4 book ai didi

php - 警告: mysqli_fetch_assoc() expects exactly 1 parameter, 2 given

转载 作者:行者123 更新时间:2023-12-03 09:05:56 24 4
gpt4 key购买 nike

我遇到了一个小问题...我花了一些时间尝试创建mysqli登录脚本,但是除了遇到问题外没有做任何事情...我尝试了很多事情,但是每次都出错。现在我来了一个无法再独自解决问题的时代。我得到的错误是“警告:mysqli_fetch_assoc()期望参数1为mysqli_result,在D处给出的对象:-FTP- WEB- WEB 5.0 \ index.php,在第26行” -我的代码是:

<?php  
$connect = mysqli_connect("localhost", "root", "", "testing");
session_start();
if(isset($_SESSION["username"]))
{
header("location:entry.php");
}

if(isset($_POST["login"]))
{
if($_POST["username"] == '' || $_POST["pin"] == '')
{
echo '<script>alert("Alle felter SKAL udfyldes!")</script>';
}
else
{
$username = mysqli_real_escape_string($connect, $_POST["username"]);
$password = mysqli_real_escape_string($connect, $_POST["password"]);
$pin = mysqli_real_escape_string($connect, $_POST["pin"]);
$password = sha1($password);
$pin = sha1($pin);
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$row = mysqli_fetch_assoc($connect, $result) ;
$pass = $row['password'] ;
$check_pin = $row['pin'] ;

if ($password === $pass && $pin === $check_pin){
$_SESSION['username'] = $username;
header("location:entry.php");
}
}
else
{
echo '<script>alert("Forkert brugernavn, adgangskode eller pin-kode")</script>';
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<script>
var loc = window.location.href+'';
if (loc.indexOf('http://')==0){
window.location.href = loc.replace('http://','https://');
}
</script>
<title>
MJVS - Private area.
</title>
<link rel="shortcut icon" href="/title_logo.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head>
<body>
<br /><br />
<div class="container" style="width:500px;">
<h3 align="center"></h3>
<br />
<h3 align="center"><b>Login</b></h3>
<br />
<form method="post">
<label>Enter Username</label>
<input type="text" name="username" class="form-control" />
<br />
<label>Enter Password</label>
<input type="password" name="password" class="form-control" />
<br />
<label>Enter PIN</label>
<input type="password" name="pin" class="form-control" maxlength="4" />
<br />
<input type="submit" name="login" value="Login" class="btn btn-info" />
<br />
</form>
<?php

?>
</div>
</body>
</html>


我希望任何人都可以帮助我解决我的问题...

最佳答案

看看documentation。该函数采用一个参数。特别是在您的情况下,$result参数是

Procedural style only: A result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result()



您给它两个。仅传递结果变量。

分解,您有:
$result = mysqli_query($link, $query)

获得结果集的位置(其中 $link表示您的连接),以及
$row = mysqli_fetch_assoc($result)

获得通用行。该文档本身有两个示例。

关于php - 警告: mysqli_fetch_assoc() expects exactly 1 parameter, 2 given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50981373/

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