Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Konrad Pilch
Konrad Pilch
2,435 Points

It doesnt display the name in the welome not the others

Hi, This is the code:

<?php

    error_reporting(E_ALL & ~E_NOTICE);
    session_start();

    if (isset($_SESION['id'])) {
        $userId = $_SESION['id'];
        $username = $_SESSION['username'];
    }   else {

    }

?>

<!DOCTYPE>
<html>
<head>
    <title>Secret User Page</title>
</head>
<body>

    <h1> Welcome, <?php echo $username; ?>. You are logged in. Your use ID <?php echo $userId; ?>. 
        <br /> 
        <br />

        <form action="logout.php">
            <input type="submit" value="Log me Out!" />
        </form>

</body>
</html>

I logged in and everything... but now, it doest display the Name in the echo and the user id in the echo in the html.

Is there something very simple or misspelled i did? i cant find anything wrong here.

Konrad Pilch
Konrad Pilch
2,435 Points

Also, if i add the die() , the else statement like here:

<?php

    error_reporting(E_ALL & ~E_NOTICE);
    session_start();

    if (isset($_SESION['id'])) {
        $userId = $_SESION['id'];
        $username = $_SESSION['username'];
    }   else {
        header('Location: index.php');
        die();
    }

?>

<!DOCTYPE>
<html>
<head>
    <title>Secret User Page</title>
</head>
<body>

    <h1> Welcome, <?php echo $username; ?>. You are logged in. Your use ID <?php echo $userId; ?>. 
        <br /> 
        <br />

        <form action="logout.php">
            <input type="submit" value="Log me Out!" />
        </form>

</body>
</html>

It doesnt work.

1 Answer

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,696 Points

Konrad,

Watch your spelling. You have both SESION and SESSION in your code; the latter being the correct spelling.

if (isset($_SESSION['id'])) { 
        $userId = $_SESSION['id']; 
        $username = $_SESSION['username'];
...

ā€“ Rich

Konrad Pilch
Konrad Pilch
2,435 Points

xd thank you. The ID number now works fine, but the Name doesnt work although i checked the spelling and did what you showed me.

Konrad Pilch try echoing just this $_SESSION['username'] and see what you get. If nothing is printed, then that variable is empty which means it was never sent from the browser to the server -- perhaps it's not called "username" in your html? Maybe you forgot to add a name=username attribute to that html-element?

Konrad Pilch
Konrad Pilch
2,435 Points

Theres nothing in it. Its strange because in the database, its same as in the code. And i have checked all the = signs . The ID works, the name doesnt. When i take out the SESSION, it displays the name as 'Array'.