我想创建登录页面。首先,我从login.html获取用户名和密码,并将它们发送到login.php以检查其是否可用。但它总是会出错,我无法解决这个问题
的login.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>
的login.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
答案 0 :(得分:0)
$query
变量不应为mysqli_query
,而应为字符串,因为您不能将查询作为参数传递给另一个查询。将该行(24)替换为此:
$query = "SELECT * FROM studenttable WHERE username='$username' and password='$password'";