Witam, piszę apkę webową i zaczynam od Panelu Logowania. Napisałem kod klasy łączącej się z bazą danych, wstępne logowanie bez weryfikacji danych, oraz formularzyk w HTMLu. Mam jakiś niewielki problem z zalogowaniem się i nie mogę się go doszukać. Jak klikam login to wyświetla mi: Incorrect username or password. Proszę o pomoc.
User.php:
<?php
/**
* Created by PhpStorm.
* User: ziben
* Date: 18.10.2015
* Time: 17:41
*/
include_once('ConnectionDB.php');
class User
{
private $db;
public function __construct(){
$this->db = new ConnectionDB();
$this->db = $this->db->getConnection();
}
public function Login($name,$pass){
if(!empty($name) && !empty($pass)){
$st = $this->db->prepare("select * from users where name=? and pass=?");
$st->bindParam(1, $name);
$st->bindParam(2, $pass);
$st->execute();
if($st->rowCount() > 0){
echo "User verified, Access granted.";
} else {
echo "Incorrect username or password";
}
}else{
echo "Please enter username and password";
}
}
}
index.php
<?php
/**
* Created by PhpStorm.
* User: ziben
* Date: 18.10.2015
* Time: 14:42
*/
include_once('User.php');
if(isset($_POST['submit'])){
$name = $_POST['user'];
$pass = $_POST['pass'];
$object = new User();
$object->Login($name, $pass);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Panel logowania</title>
</head>
<body>
<form method="post" action="index.php">
Login: <input type="text" name="user"/>
Password: <input type="password" name="pass"/>
<input type="submit" name="submit" value="Login"/>
</form>
</body>
</html>
ConnectionDB.php <- tu jest raczej dobrze, jedyny problem jest taki, że jak odświeżę index.php to tak jakby odświeża, film przedstawia sytuację: http://speedy.sh/HkgSA/2015-10-18-at-19-52-21.mp4
<?php
/**
* Created by PhpStorm.
* User: ziben
* Date: 17.10.2015
* Time: 20:31
*/
class ConnectionDB{
//Specyfikacja bazy danych
private $host = "localhost";
private $base = "mojabaza";
private $username = "admin";
private $password = "admin";
public $conn;
//Połączenie z bazą danych
public function getConnection(){
$this->conn = null;
try{
$this->conn = new PDO("mysql:host=" .$this->host . ";base=" . $this->base, $this->username, $this->password);
}catch(PDOException $exception){
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
i zdjęcie z phpMyAdmin:
Z góry dzięki za wszelką pomoc.
Maciej Cąderek