Jump to content

Members area in php and database


Devfren

Recommended Posts

Bonjour, je suis nouveau sur le forum et j'aimerais avoir votre aide.

Mon problème est le suivant. 

J'ai créé un espace membres sur mon site Web et je souhaite que chaque utilisateur connecté puisse voir combien de points ils ont à disposition. J'aimerais donc l'appeler à partir de ma base de données et afficher chaque utilisateur individuellement en fonction de sa session. 

Merci d'avoir lu j'aimerais beaucoup

Link to comment
Share on other sites

1 hour ago, Devfren said:

i just want an example

Store id if login successful

    if (password_verify($_POST['password'], $row['password'])) {
        $_SESSION['user_id'] = $_POST['user_id'];
    }
    else {
        // error - invalid login
    }

Get and display points

    if (isset($_SESSION['user_id'])) {   
        $res = $conn->prepare("SELECT points
                               FROM user_points
                               WHERE user_id = ?
                              ");
        $res->execute([${SESSION['user_id']}]);
        echo "You have " . $res->fetchColumn(). " points<br>";
    }
    else {
        header("Location: login.php");                // send to login page
    }

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.