gpt4 book ai didi

php - mysqli_num_rows 始终返回 0

转载 作者:行者123 更新时间:2023-11-29 17:26:14 25 4
gpt4 key购买 nike

这里尝试从数据库获取用户名和密码,如果找到结果,则重定向到某个页面,但 mysqli_num_rows 总是返回 0,我不知道为什么`

    if (isset($_POST['login'])) {


$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM `login` WHERE username = '$username' AND password = '$password'";
$run = mysqli_query($con,$query);
if (mysqli_num_rows($run) == 1) {
header("location: login.php");

}}?>

` Here is my DB tables and columns

最佳答案

        <?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ornament"; // My local DB Name

$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$username = "test"; // $_POST["username"] value
$password = "test"; // $_POST["password"] value
$sql = "SELECT * FROM `ornament` WHERE username = '$username' AND password = '$password'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) == 1) {
echo "correct";

} else {
echo "wrong";
}



mysqli_close($conn);
?>

</body>
</html>

输出:

     correct

我有一个数据库名称和表名称相同,但对我来说它工作正常。

注意:请检查您在 POST 获取时是否使用了正确的密码。

无论您如何找到解决方案,祝您有美好的一天

谢谢

穆图

关于php - mysqli_num_rows 始终返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50947879/

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