This question already has an answer here:
- Undefined variable: $_SESSION 2 answers
Here is my php code:
<?php include("inc/incfiles/header.inc.php")?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Index</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Welcome <?php echo ($_SESSION['SESS_fname']);?></h1>
<a href="member-profile.php">My Profile</a> | <a href="logout.php">Logout</a>
<p>This is a password protected area only accessible to members. </p>
</body>
</html>
I know something I wrong with the code but I don't know how to fix it. My error says: "Notice: Undefined variable: _SESSION in C:\xampp\htdocs\Smasher\member-index.php on line 9"
How can I fix the error so it will say the user's first name? The first name in the database table on mySQL is called fname
.
Add
at the beginning of your page before any HTML
You will have something like :
Don't forget to remove the space you have before
First, you'll need to add
session_start()
at the top of any page that you wish to useSESSION
variables on.Also, you should check to make sure the variable is set first before using it:
Or, simply: