0

I want to create login page. First, I get username and password from login.html and send them to login.php to check its available or not. But it always give errors and I cannot solve that

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.';
            }
      }
}
?>

ERRORS login.php

12
  • problem here : $query = mysqli_query("SELECT * FROM studenttable WHERE username='$username' and password='$password'"); Should be : $query = "SELECT * FROM studenttable WHERE username='$username' and password='$password'"; Commented Nov 20, 2017 at 23:17
  • can you help me have to solve that problem Commented Nov 20, 2017 at 23:18
  • edited my comment. Commented Nov 20, 2017 at 23:19
  • stupid mistake. thank you but it is not enough. There is one more error. Its Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\login.php on line 25 Commented Nov 20, 2017 at 23:20
  • so $res returned false , check your query . Commented Nov 20, 2017 at 23:22

1 Answer 1

0

The $query variable should not be a mysqli_query, but a string, since you can't pass a query as a parameter to another query. Replace that line (24) with this:

$query = "SELECT * FROM studenttable WHERE username='$username' and password='$password'";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.