Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have my code for a member system and this line of code checks if the user has logged in to display his/her name but I am getting errors.

PHP
<?php
		// Check if username session is set or not 
		//if it is set then say Hi with the username
		//If it is not then display login/Register
		if (!isset($_SESSION['user'])) {
			echo "$lgrreg";
		}else{
			echo "Hi $username! ";
		}
			
		$lgout = '<a href="logout.php">Logout?</a>';
			
		$lgrreg = '<a href="membersys.php">
		Login/Register
		</a>';
?>


At :
Line 26: $lgrreg = '<a href="membersys.php">

I have some errors

Notice: Undefined variable: lgrreg in C:\xampp\htdocs\index.php on line 26



But how have I not defined it?
Posted
Updated 31-Dec-13 9:08am
v2

1 solution

As I see, the message itself looks a little bit confusing, becouse the problem is elsewhere. But look this way: in the if statement you are echoing that variable, but at that point it is undefined. I suggest you put the whole if statement at the end of the section, after you set those two variables. Should not make any difference, but try to avoid multiline string constant for a try.
 
Share this answer
 
v2
Comments
Braydon 31-Dec-13 19:22pm    
Thanks for the tip got it fixed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900