Bonjour,
Après avoir suivi, dans l'ordre:
- Gestion dun espace membre en PHP
- Créer un panier en PHP
Je suis bloquer quand j'essaie de me connecter, il me dit "Fatal error: Call to a member function execute() on array in C:\wamp\www\account\login.php on line 12" ..
Mes pages PHP
Voici mon arborescence: https://prnt.sc/fbistx
login.php
<?php
include('../includes/head.php');
require_once '../includes/functions.php';
reconnect_from_cookie();
if (isset($_SESSION['auth'])) {
header('Location: index.php');
exit();
}
if (!empty($_POST) && !empty($_POST['username']) && !empty($_POST['password'])){
require_once '../includes/database.php';
$req = $pdo->query('SELECT * FROM users WHERE (username = :username OR email = :username) AND confirmed_at IS NOT NULL');
$req->execute(['username' => $_POST['username']]);
$user = $req->fetch();
if (password_verify($_POST['password'], $user->password)) {
$_SESSION['auth'] = $user;
$_SESSION['flash']['success'] = 'Vous êtes maintenant connecté';
if ($_POST['remember']) {
$remember_token = str_random(250);
$pdo->prepare('UPDATE FROM users SET remember_token = ? WHERE id = ?')->execute([$remember_token, $user->id]);
setcookie('remember', $user->id . '==' . $remember_token . sha1($user->id . 'test'), time() + 60 * 60 * 24 * 7);
}
}else {
$_SESSION['flash']['danger'] = 'Identifiant ou mot de passe incorrect';
}
}
?>
database.php
<?php
class database{
private $host = 'localhost';
private $username = 'root';
private $password = '';
private $database = 'floris';
private $pdo;
public function __construct($host = null, $username = null, $password = null, $databse = null){
if ($host != null) {
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
try {
$this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->username, $this->password, array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8',
PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ
));
} catch (PDOException $e) {
die();
}
}
public function query($sql, $data = array()){
$req = $this->pdo->prepare($sql);
$req->execute($data);
return $req->fetchAll(PDO::FETCH_OBJ);
}
}
head.php
<?php
require_once '_header.php';
?>
_header.php
<?php
require_once 'panier.class.php';
require_once 'database.php';
$pdo = new database();
$panier = new panier($pdo);
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
Quelqu'un aurait une solution?
Merci d'avance <3