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 trialKonrad Pilch
2,435 PointsIt 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.
1 Answer
Rich Donnellan
Treehouse Moderator 27,696 PointsKonrad,
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
2,435 Pointsxd thank you. The ID number now works fine, but the Name doesnt work although i checked the spelling and did what you showed me.
Christian Andersson
8,712 PointsKonrad 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
2,435 PointsTheres 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'.
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsAlso, if i add the die() , the else statement like here:
It doesnt work.