-1

I get this message:

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Password' in 'field list' in C:\xampp\htdocs\eCommerce\admin\index.php:26 Stack trace: #0 C:\xampp\htdocs\eCommerce\admin\index.php(26): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\eCommerce\admin\index.php on line 26

It says that the error comes from this line:

$stmt->execute(array($username, $hashedPass));

<?php
    session_start();
    $noNvabar = '';

    if(isset($_SESSION['Username'])){

        header('Location: dashboard.php');//Redirect to dashboard page
    }

    include 'init.php';


    // Check if the user coming from an http post request

    if ($_SERVER['REQUEST_METHOD'] == 'POST'){

        $username = $_POST['user'];
        $password = $_POST['pass'];
        $hashedPass = sha1($password);

        // Check if the user exist in the database

        $stmt = $con->prepare("SELECT Username, Password FROM users WHERE Username = ? AND Password = ?");

        $stmt->execute(array($username, $hashedPass));
        $count = $stmt->rowCount();


        // If count > 0 this means the database contains record about this username

        if ($count > 0) {

            echo 'welcome' . $username;
            $_SESSION['Username'] = $username; // Register Session Nmae
            header('Location: dashboard.php'); // Redirect to dashboard page
            exit();
        }
    }
?>

<form class="login" action="<?php echo $_SERVER['PHP_SELF'] ?>"    method="POST">
    <h4 class="text-center">Admin Login </h4>

    <input class="form-control" type="text" name="user"    placeholder="Username" autocomplete="off" />

    <input class="form-control" type="password" name="pass"   placeholder="Password" autocomplete="new-Password" />

    <input class="btn btn-primary btn-block " type="submit" value="login"       />
</form>

<?php
    include $tbl . 'footer.php';
?>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alaa MH
  • 13
  • 1
  • 2

1 Answers1

2

Please read the message:

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Password' in 'field list' in C:\xampp\htdocs\eCommerce\admin\index.php:26

==>

    $stmt = $con->prepare("SELECT Username, Password FROM users WHERE Username = ? AND Password = ?");

Password is not found in the users table.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kosar Latif
  • 116
  • 4
  • Yes, but what is the conclusion (besides the obvious)? There could be several possible solutions (and (most common) reasons for this problem). Respond by [editing your answer](https://stackoverflow.com/posts/50290014/edit), not here in comments. – Peter Mortensen Apr 21 '20 at 02:14