/    Sign up×
Community /Pin to ProfileBookmark

Parse Error with my login script (sort of)

I have a script that is suppose to show the login box when someone isn’t logged in but shows the user’s username when succesfully logged in. But I get a Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in /var/www/subdomain/menus/user/user.php on line 4 and the login box doesn’t even show up. Why and how can I fix this.

[code=php]<?php
session_start();
if (!$_SESSION[‘username’]) {
echo “You are logged in as ($_SESSION[‘username’])”;
} else {
include(“form.html”);
}
?>[/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsFeb 12.2006 — Use {} isntead of () for parsing inside of strings

[code=php]<?php
session_start();
if (!$_SESSION['username']) {
echo "You are logged in as {$_SESSION['username']}";
} else {
include("form.html");
}
?>[/code]
Copy linkTweet thisAlerts:
@BOB101authorFeb 12.2006 — Know when I add the {} i get a Parse error: parse error, expecting ','' or ';'' in /var/www/subdomain/menus/user/user.php on line 4. Why?

[code=php]<?php
session_start();
if (!$_SESSION['username']) {
echo 'You are logged in as {$_SESSION['username']} || <a href="user/logout.php">Logout</a>';
} else {
include("form.html");
}
?>[/code]
Copy linkTweet thisAlerts:
@bokehFeb 12.2006 — Variables are not accessible from inside a single quoted string literal. Also your if/else logic is wrong. It reads:[I] if $_SESSION['username'] has no value print it otherwise print the form[/I].
Copy linkTweet thisAlerts:
@BOB101authorFeb 12.2006 — Variables are not accessible from inside a single quoted string literal.[/QUOTE] What the freak does that mean? Dump it down, I'm just a noob at php. And are you saying get rid of the echo and use print or get rid of the include thing and just type out the form?
Copy linkTweet thisAlerts:
@bokehFeb 13.2006 — The string you wish to print is encapsulated within single quotation marks. When this is the case all characters are printed as exactly they appear in the string.

String literal: [I]A contiguous sequence of zero or more characters enclosed in quotation marks that is itself data, rather than a reference to data[/I]

Try to learn the vocabulary and then you will understand explanations better. It's a bit like going to hospital with a pain in the leg and when the doctor says the bone is broken telling him "[I]please dumb it down doctor... I'm a newb when it comes to hospitals... what is a bone?[/I]"
Copy linkTweet thisAlerts:
@SpectreReturnsFeb 13.2006 — Now that you've changed it to single quotes, a) it won't parse variables, and b) you can't use unescaped 's.

Should be:
[code=php]<?php
session_start();
if (!$_SESSION['username']) {
echo 'You are logged in as '. $_SESSION['username'] .' || <a href="user/logout.php">Logout</a>';
} else {
include("form.html");
}
?>[/code]


Also, I agree with bokeh. Learn atleast the basics before you come asking for help.

And, just for the record, Napoleon Dynamite was a horrible, horrible movie.
Copy linkTweet thisAlerts:
@bokehFeb 13.2006 — Also as I mentioned earlier I have trouble with this:[CODE]if ([color=red]![/color]$_SESSION['username']) {[/CODE]
Copy linkTweet thisAlerts:
@BOB101authorFeb 13.2006 — SpectreReturns I didn't ask for your dang opinion about the movie and I think it was pretty funny (for a movie with no plot). And thanks.
Copy linkTweet thisAlerts:
@SpectreReturnsFeb 13.2006 — Also as I mentioned earlier I have trouble with this:[CODE]if ([color=red]![/color]$_SESSION['username']) {[/CODE][/QUOTE]
You're right. I just copied his code. Correct source should be:
[code=php]<?php
session_start();
if ($_SESSION['username']) {
echo 'You are logged in as '. $_SESSION['username'] .' || <a href="user/logout.php">Logout</a>';
} else {
include("form.html");
}
?> [/code]
Copy linkTweet thisAlerts:
@BOB101authorFeb 13.2006 — Thanks alot guys, I got rid of the exclamation mark and it works now, just need to register and account and try it. Thanks again.
×

Success!

Help @BOB101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...