gpt4 book ai didi

PHP 登录问题 - mysql_num_rows 无效

转载 作者:行者123 更新时间:2023-11-30 00:45:16 25 4
gpt4 key购买 nike

祝大家有美好的一天好吧,我有登录问题,每次我尝试登录时都会收到此消息

  1. 警告:mysql_query():提供的参数不是有效的 MySQL-Link在线/home/a6720525/public_html/functions/sandbox.php 中的资源25

  2. 警告:mysql_num_rows():提供的参数不是有效的 MySQL结果资源位于/home/a6720525/public_html/functions/sandbox.php第 27 行

登录表单

 <form class="admin_login" id="form1" name="form1" method="post" action="index.php">

<input class="username" name="username" type="text" id="username" size"40" placeholder="Adress email"/>

<input class="userpass" name="password" type="password" id="password" size"40" placeholder="Mot de pass"/>

<input class="addbutton" type="submit" name="button" value="connexion"/>
<input class="addbutton" type="submit" name="insc" value="Inscription"/>
<input class="addbutton" type="submit" name="mpo" value="Mot de pass oublier?"/>
</form>

我使用的功能

function members ($dbc, $qu) {

if(isset($_POST["username"])&& isset($_POST["password"])){
$manager = preg_replace('#[^A-Za-z0-9\@\-\_\|\,\.\\p{L}\\\\]#i', '', $_POST["username"]);//filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]);// filter everything but numbers and letters
// Connect to the Mysql database
$qu = "SELECT id FROM users WHERE username='$manager' AND password='$password' LIMIT 1";
$re = mysql_query($dbc, $qu);
//........make sure person exists in data base
$existCount = mysql_num_rows($re);// count the row nums
if($existCount == 1){//evaluate the count
while($row = mysql_fetch_array($re )){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $manager;
$_SESSION["password"] = $password;
header("location:index.php");
exit();
}else{
echo 'That information is incorrect,try again <a href="index.php">Click Here</a>';
exit();
}
}
}

最佳答案

session_start();
if(isset($_POST["username"])&& isset($_POST["password"])){
$manager = preg_replace('#[^A-Za-z0-9\@\-\_\|\,\.\\p{L}\\\\]#i', '', $_POST["username"]);//filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]);// filter everything but numbers and letters
// Connect to the Mysql database
$q = "SELECT * FROM users WHERE username='$manager' AND password='$password' LIMIT 1";
$r = mysqli_query($dbc, $q);
$userCount = mysqli_num_rows($r);
if($userCount == 1 ) {
while ($user = mysqli_fetch_assoc($r)) {

$id = $user['id'];
$pass = $user['password'];
$us = $user['username'];

}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $us;
$_SESSION["password"] = $pass;
header("location:index.php?page=business");
exit();

}else { echo 'That information is incorrect,try again <a href="index.php">Click Here</a>';
}


}

关于PHP 登录问题 - mysql_num_rows 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21433618/

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