I'm making a login system using PDO and my code got some issues.
My problem is when i press the submit button i got an error that says :
"Fatal error: Class 'User' not found
" in my index.php.
Does anyone can help me find the solution to my problem please.
index.php:
<?php
session_start();
include_once('connection.php');
if(isset($_POST['submit'])){
$user = $_POST['user'];
$pass = $_POST['pass'];
$object = new User();
$object->Login($user, $pass);
}
?>
<html lang="en">
<head>
</head>
<body>
<form method="post" action="index.php">
Username: <input type="text" name="user" />
Password: <input type="text" name="pass" />
<input type="submit" name="submit" value="Login" />
</form>
</body>
</html>
user.php:
<?php
include_once('connection.php');
class User{
private $db;
public function __construct(){
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function Login($user, $pass){
if(!empty($user) && !empty($pass)){
$st = $this->db->prepare("SELECT * from users WHERE username=? AND password=?");
$st->bindParam(1, $user);
$st->bindParam(2, $pass);
$st->execute();
if($st->rowCount() == 1){
echo "User verifies, Access granted";
} else {
echo "Incorrect Username or Password";
}
}else{
echo "Please enter Username and Password";
}
}
}
?>
connection.php:
<?php
class Connection{
public function dbConnect(){
return new PDO('mysql:host=localhost; dbname=test', 'root', 'password');
}
}
?>
user.php
?