What I am trying to do is once a user has entered their username and password, they will be directed to another pager (index.php), otherwise it stays on l the login page. However, when I enter in test username and password I get an error message -- Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\MyCMS\admin\login.php on line 13.
the php code is:
<?php
# start session
session_start();
# databaase connection
include('config/setup.php');
if($_POST) {
$q = "SELECT * FROM users WHERE user-email = '$_POST[email]' AND password = SHA1('$_POST[password]')";
$r = mysqli_query($dbc, $q);
if(mysqli_num_rows($r) == 1) {
$_SERVER['username'] = $_POST['email'];
header('Location: index.php');
}
}
?>
The HTML code (form):
<form role="form" action="login.php" method="post">
<div class="form-group">
<label for="Email">Email address</label>
<input type="email" class="form-control" id="Email" name="email" placeholder="Email">
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="password" class="form-control" id="Password" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
The sql table headers:
id first-name last-name user-email password
I placed a test code (php) to see if username and password are sent. The code:
<?php
if($_POST) {
echo $_POST['email'];
echo '<br>';
echo $_POST['password'];
}
?>
This works - in that is echos to the screen.
What is causing the error.
Thanks in advance