【发布时间】:2025-12-02 11:10:02
【问题描述】:
我想创建登录页面。首先,我从 login.html 获取用户名和密码并将它们发送到 login.php 以检查其是否可用。但它总是给出错误,我无法解决这个问题
登录.html
<form action="login.php" method="post">
<div class="containerLogin">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username"name="username" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
</div>
<div class="containerLogin" style="background-color:#f1f1f1">
<input type="submit" name="submit" value="submit" class="btn btn-primary">
<span class="password">Forgot <a href="#">password?</a></span>
</div>
</form>
登录.php
<?php
include_once "connection.php";
if (isset($_POST['submit'])) {
session_start();
if($_POST['username'] && $_POST['password']) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = mysqli_query("SELECT * FROM studenttable WHERE username='$username' and password='$password'");
$res = mysqli_query($con, $query);
$count_user = mysqli_num_rows($res);
if($count_user==1)
{
$row = mysqli_fetch_array($res);
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
header("location:dashboard.php?success=1");
}else{
$error = 'Incorrect Username, Password and Branch.';
}
}
}
?>
错误 login.php
【问题讨论】:
-
这里的问题:
$query = mysqli_query("SELECT * FROM studenttable WHERE username='$username' and password='$password'");应该是:$query = "SELECT * FROM studenttable WHERE username='$username' and password='$password'"; -
你能帮我解决这个问题吗
-
编辑了我的评论。
-
愚蠢的错误。谢谢,但这还不够。还有一个错误。其警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,在第 25 行的 C:\login.php 中给出的布尔值
-
所以 $res 返回 false ,请检查您的查询。
标签: php jquery html mysql database