php mysqli_query() 错误
Posted
技术标签:
【中文标题】php mysqli_query() 错误【英文标题】:php mysqli_query() ERRORS 【发布时间】:2018-05-04 07:14:36 【问题描述】:我想创建登录页面。首先,我从 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 ,请检查您的查询。
【参考方案1】:
$query
变量不应是 mysqli_query
,而是字符串,因为您不能将查询作为参数传递给另一个查询。将第 (24) 行替换为:
$query = "SELECT * FROM studenttable WHERE username='$username' and password='$password'";
【讨论】:
以上是关于php mysqli_query() 错误的主要内容,如果未能解决你的问题,请参考以下文章