Adam
Adam

Reputation: 67

How can I get data from MySQL for each user

I need help. I crated a MySQL database and I connected database with login and registration form. All it´s working. I tried to create page that show all data about user from database. I created tried this code:

<p>Username: <?php echo $_SESSION['username']; ?></p>
<p>Email: <?php echo $_SESSION['email']; ?></p>
<p>Create profile date and time: <?php echo $_SESSION['create_datetime']; ?></p>

But that showed me only username. I created this from this page. Can you help me with this? Very much thanks for response!

Upvotes: 0

Views: 74

Answers (1)

Amit Sarker
Amit Sarker

Reputation: 56

Inside login.php page you need to assign email and create_datetime to $_SESSION. It should be like

if ($rows == 1) {
        while($row = $result->fetch_assoc()) {
            $_SESSION['username'] = $row["username"];
            $_SESSION['email'] = $row["email"];
            $_SESSION['create_datetime'] = $row["create_datetime"];
        }
        // Redirect to user dashboard page
        header("Location: dashboard.php");
    }

Upvotes: 3

Related Questions