I've been working on a login page for some time now, but every time I try to log in, I get the message 'Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given'. Any ideas on how to fix this issue?
<?php
session_start();
if (isset($_POST['username'])) {
include_once("dbconnect.php");
$usname = strip_tags($_POST["username"]);
$paswd = strip_tags($_POST["password"]);
$usname = mysqli_real_escape_string($dbCon, $usname);
$paswd = mysqli_real_escape_string($dbCon, $paswd);
$sql = "SELECT id, username, password FROM users WHERE username = '$usname' AND activated = '1' LIMIT 1";
$query = mysqli_query($dbCon, $sql);
$row = mysqli_fetch_row($query);
$uid = $row[0];
$dbUsname = $row[1];
$dbPassword = $row[2];
if ($usname == $dbUsname && $paswd == $dbPassword) {
// Set session variables
$_SESSION['username'] = $usname;
$_SESSION['id'] = $uid;
$msg = " ";
$msg = "username: ".$usname." dbusername: ".$dbUsname;
// Now direct to users feed
//header("Location: user.php");
} else {
$msg = "<h2>That username or password is incorrect dumbass.</h2>";
}
} else {
$msg = " ";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link href="css/reset.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<title>Campus Key</title>
</head>
<body>
<header>
<a href="#"> <img src="logowhite.png" alt="Campus Key" style="width:150px;height:41px"></a>
</header>
<nav class="navigation">
<div class="non_registerd">
<h2><a class="button" href="#">Logged-in user's name</a></h2>
</div>
</nav>
<form id="form" action="login.php" method="post" enctype="multipart/fprm-data">
<?php
echo $msg;
?><br>
URI Email: <input class="input" id="email" type="text" name="username" value="user@my.uri.edu" size="30"><br>
Password: <input class="input" id="pass" type="password" name="password" size="30"><br>
<input class="button" type="Submit" name="submit" value="Login"><br>
</form>
</body>
<footer>
<p><FONT color="#ffffff">Campus Key © Whatever We Want</color></p>
</footer>
</html>