Voici le code des pages concernées :

Profil.php

<?php require 'includes/en-tete.php'; ?>
<?php 
    session_start();
    if(!isset($_SESSION'identifiant']))
    {
        header('Location: connexion.php');
        exit;
    }
?>
<div class="container">
    <h3>
        Vos informations personnelles 
    </h3>
    <div class="alert alert-info">
        <?php
            echo 'Bienvenue sur votre profil <strong>', htmlspecialchars($_SESSION'identifiant']);
        ?>
    </div>
    <p>
        Mon identifiant : 
    </p>
    <p>
        Mon Adresse Email :
    </p>
    <p>
        Mon Prénom :
    </p>
    <p>
        Mon Nom : 
    </p>
    <p>
        Ma Biographie : 
    </p>
    <a href="tchat.php">
        <button type="button" class="btn btn-success btn-lg btn-block">
            Je veux accèder au coin détente.
        </button>
    </a>
        <br />
    <a href="edit-profilVoici .php">
        <button type="button" class="btn btn-info btn-lg btn-block">
            Je veux modifier mes informations personnelles.
        </button>
    </a>
        <br />
    <a href="controllers/deconnexion.php">
        <button type="button" class="btn btn-danger btn-lg btn-block">
            Je veux me déconnecter de mon profil.
        </button>
    </a>
</div>
<?php require 'includes/pied-page.php'; ?>

Connexion.php

<?php 
    session_start(); 
    if(isset($_POST'identifiant'], $_POST'password']))
    {
        $dns = 'mysql:host=localhost;dbname=espace_membres';
        $utilisateur = 'root';
        $motDePasse = '';
        $bdd = new PDO( $dns, $utilisateur, $motDePasse );
        $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $req = $bdd->prepare('SELECT * FROM profil WHERE identifiant= :identifiant AND password = SHA(:password)');
        $req->execute(array(
            'identifiant' => $_POST'identifiant'],
            'password' => $_POST'password'],
        ));
        if($user = $req->fetch(PDO::FETCH_ASSOC))
        {
            $_SESSION'id'] = $user'id'];
            $_SESSION'identifiant'] = $user'identifiant'];
            header('Location: ../profil.php');
        }else{
            echo 'Cet identifiant ou mot de passe n\'existe pas ou sont incorrect';
        }
    }else{
        echo 'Un ou plusieurs champs sont vides.';
    }
?>

Donc voilà le but, c'est de récupérer les infos de l'utilisateur qui vient de se connecter sur son profil
pour afficher ses informations

  • J'ai essayé mais sa affiche les infos de tous les utilisateurs

Merci.

2 réponses


Glaived
Réponse acceptée

Correction, c'est

$sql = 'SELECT * FROM profil WHERE identifiant=:identifiant AND password=:password';
$req = $bdd->prepare($sql);
$req->execute(array(
    'identifiant' => $_POST'identifiant'],
    'password' => sha1($_POST'password']),
));

« Faut mettre des ' ou " quand ton bind est un string » FAUX , il ne FAUT PAS en mettre dans le cas de binds

essai ça

$sql = 'SELECT * FROM profil WHERE identifiant=":identifiant" AND password=":password"';
$req = $bdd->prepare($sql);
$req->execute(array(
    'identifiant' => $_POST'identifiant'],
    'password' => sha1($_POST'password']),
));

Faut mettre des ' ou " quand ton bind est un string

http://www.grafikart.fr/forum/topic/13344 ton sujet est résolu ? si oui, mes le en résolu ^^