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 trialOsama Awan
Courses Plus Student 8,676 PointsUndefined variable
when i try to echo $role variable in html <p> tag php interpreter gives an error Notice: Undefined variable: location in /home/treehouse/workspace/index.php on line 29
5 Answers
Nicholas Jacob
7,536 PointsHas the $role variable been assigned a value? For example:
$role = "some value";
If so, make sure your syntax is correct. For example, maybe you're missing a semi-colon at the end of the statement.
Antonio Nicasio
Courses Plus Student 3,601 Points$variable = 'yourdata';
can put your code to see what's going on?
Samuel Tissot-Jobin
7,350 PointsThere is no code snippet so I can't be sure but usually a "NOTICE" like that probably means that you are accessing a variable that has not been declared yet.
//this will create the error
echo $variable;
//this won't
$variable = '';
echo $variable;
it's a question of initializing the variable to something before accessing it.
Mohamed Hak
17,195 PointsI think this is not your first time learning PHP, and it seems you configured PHP to handle errors. maybe that's why it show you that there is something wrong with your syntax. hope this helps.
James Pask
13,600 PointsI guess this is expected behaviour although it doesn't show on Hamptons videos. Presumably you get the error when you're not a student or teacher and have "Foo" in the $role variable?
I get the same but I'm assuming this is because neither of the two scenarios apply and we're not definining the $info variable.. yet. Hopefully this will be picked up as the video progresses.
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 PointsCan you please post the code you are having trouble with.