gpt4 book ai didi

php - 无法运行查询 : ??没有查询错误消息让我无处可去

转载 作者:行者123 更新时间:2023-11-29 06:55:55 24 4
gpt4 key购买 nike

所以我有这个验证码。除了我输入错误的用户名外,其他一切都有效。它只是一直显示在页面中:“无法运行查询:” <-- 只有这个。我不知道出了什么问题。请帮忙。

这是我的那部分代码:

if($UserN){
if($UserP){
require("connect.php");

$query = mysql_query("SELECT * FROM customer WHERE UserName = '$UserN'");
$numrows = mysql_num_rows($query) or die ('Unable to run query:'.mysql_error());

if($numrows == 1){
$row = mysql_fetch_assoc($query)or die ('Unable to run query:'.mysql_error()); // fetch associated: get function from a query for a database
$dbpass = $row['PassWord']; // read password of inputted user from the query.
$dbuser = $row['UserName']; // read username from the query
$dbactive = $row['Active']; // read if user is active
$dbid = $row['CustNum'];

if($UserP == $dbpass){
if($dbactive == 1){
//set session information
$_SESSION['CustNum'] = $dbid;
$_SESSION['UserName'] = $dbuser;

echo "<br><br><center><b>You have been logged in as <b>$dbuser</b>. <a href='orderform.php'>Click here</a> to go to the member page.</b></center><br><br>";
}
else
echo "$form <center><b>You need to activate your account.</b></center></br>";
}
else
echo "$form <center><b>You did not enter a correct password.</b></center> </br>";
}
else
echo "$form <center><b>The username you entered was not found.</b></center></br> ";

mysql_close();
}
else
echo "$form <center><b>You must enter your password. </b></center></br>";
}
else
echo "$form <center><b>You must enter your username. </b></center></br>";

最佳答案

您的问题似乎是 mysql_num_rows() 在用户名无效的情况下返回 0。

您可以像这样调整您的代码:

$numrows = mysql_num_rows($query);
if ($numrows === FALSE)
die ('Unable to run query:'.mysql_error());
if ($numrows === 0) {
echo "User not found!";
}

注意使用 === 来测试 mysql_num_rows() 是否返回 0 或 FALSE。

关于php - 无法运行查询 : ??没有查询错误消息让我无处可去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12711446/

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