niche Posted October 12, 2010 Share Posted October 12, 2010 I found this in the cookie tutorial and it didn't work for me:<?phpif (isset($_COOKIE["user"])) echo "Welcome " . $_COOKIE["user"] . "!<br />";else echo "Welcome guest!<br />";?>I changed it to something that I thought would work, but I still get the error:Parse error: parse error in C:\wamp\www\temp109.php on line 3<?phpif (isset($_COOKIE['user'])) { echo "Welcome " . $_COOKIE['user'] . '<br />';}else { echo "Welcome guest!". '<br />';} ?>Why?PS <?PHP echo $_COOKIE['user']; ?> works for me Link to comment Share on other sites More sharing options...
Fmdpa Posted October 13, 2010 Share Posted October 13, 2010 Nothing's wrong with either script. I would usually use quotes and brackets differently, but it worked nonetheless. I tested both versions of the script, and both worked. Are you including other files, or is this the entire file? Link to comment Share on other sites More sharing options...
niche Posted October 13, 2010 Author Share Posted October 13, 2010 Now, it works for me too. Don't know what the problem was. Anyway, what's with no curly brackets? I thought they were required in an if statement.Also, what !<br/> mean? I haven't seen that before. Link to comment Share on other sites More sharing options...
birbal Posted October 13, 2010 Share Posted October 13, 2010 Now, it works for me too. Don't know what the problem was. Anyway, what's with no curly brackets? I thought they were required in an if statement.Also, what !<br/> mean? I haven't seen that before. i cant remember exactly but i saw in book like that if else..where curly bracet was not using..as far i can remember it is for short hand php. though i dont use that. i am comfortable with the bracets. as far i can remember is short hand it was writing like..if(isset($_COOKIE['something']): // it is existelse: //it doesnt exist <br/> is simply line break code from html Link to comment Share on other sites More sharing options...
niche Posted October 13, 2010 Author Share Posted October 13, 2010 what about the exclamation mark before the break? Link to comment Share on other sites More sharing options...
Synook Posted October 13, 2010 Share Posted October 13, 2010 That is part of the string. Link to comment Share on other sites More sharing options...
ShadowMage Posted October 13, 2010 Share Posted October 13, 2010 Anyway, what's with no curly brackets? I thought they were required in an if statement.It's just a shorthand. It's perfectly legal, however, I think it's only legal if an if/else will only have one statement per blockie, this is legal:if (...condition...) //do somethingelse //do something else This is not: if (...condition...) //do something //do some more stuffelse //do something else //do some more stuff Also, what !<br/> mean? I haven't seen that before.Like Synook said, it's just part of the string that will be echoed. Link to comment Share on other sites More sharing options...
thescientist Posted October 13, 2010 Share Posted October 13, 2010 Now, it works for me too. Don't know what the problem was. Anyway, what's with no curly brackets? I thought they were required in an if statement.Also, what !<br/> mean? I haven't seen that before.its part of the output, Welcome [user]! Link to comment Share on other sites More sharing options...
niche Posted October 13, 2010 Author Share Posted October 13, 2010 Oh wow. I wish I had an excuse for that last one post of mine!You all are top-notch as usual. Thanks to Fmdpa, birbal, Synook, ShadowMage, and thescientist.Niche Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.