Jump to content

[SOLVED] Code not working :/


adamjones

Recommended Posts

Hi.

 

The idea of this code is to echo some user information if the user is logged in, or if they aren't logged in, to echo a login menu;

 

<?php 
session_start();
if(session_is_registered(name)){
echo "<li class='right active'><a href='account_settings.php' rel='facebox'><span>Welcome back echo $_SESSION['name'];!</span></a></li>
<li class='right active'><a href='' rel='facebox'><span>Last login on echo $_SESSION['lastlogin'];</span></a></li>";
}
else {
echo "<li class='right logout'><a href='create.php' rel='facebox'><span>Create An Account</span></a></li>
<li class='right logout'><a href='login.php' rel='facebox'><span>Login</span></a></li>";
}
?>

 

But I get this error;

 

"Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/wowdream/public_html/designbyfreedom/habhub/index.php on line 4"

Link to comment
Share on other sites

if a varialb is already inside an echo you dont need echo again

 

try something like this

 

echo "<li class='right active'><a href='account_settings.php' rel='facebox'><span>Welcome back $_SESSION['name']!</span></a></li>
<li class='right active'><a href='' rel='facebox'><span>Last login on $_SESSION['lastlogin']</span></a></li>";

 

youll need to change your else as well

Link to comment
Share on other sites

<?php 
session_start();
if(session_is_registered(name)){
echo "<li class='right active'><a href='account_settings.php' rel='facebox'><span>Welcome back ".echo $_SESSION['name'];."!</span></a></li>
<li class='right active'><a href='' rel='facebox'><span>Last login on ".echo $_SESSION['lastlogin'];."</span></a></li>";
}
else {
echo "<li class='right logout'><a href='create.php' rel='facebox'><span>Create An Account</span></a></li>
<li class='right logout'><a href='login.php' rel='facebox'><span>Login</span></a></li>";
}
?>

 

Try that (Only fixed a few things, not the depreciated functions..)

Link to comment
Share on other sites

<?php 
session_start();
if(session_is_registered(name)){
echo "<li class='right active'><a href='account_settings.php' rel='facebox'><span>Welcome back ".echo $_SESSION['name'];."!</span></a></li>
<li class='right active'><a href='' rel='facebox'><span>Last login on ".echo $_SESSION['lastlogin'];."</span></a></li>";
}
else {
echo "<li class='right logout'><a href='create.php' rel='facebox'><span>Create An Account</span></a></li>
<li class='right logout'><a href='login.php' rel='facebox'><span>Login</span></a></li>";
}
?>

 

Try that (Only fixed a few things, not the depreciated functions..)

 

Hi, thanks. But now I get this error;

 

"Parse error: syntax error, unexpected T_ECHO in /home/wowdream/public_html/designbyfreedom/habhub/index.php on line 4"

Link to comment
Share on other sites

Youve already called echo, no need to do it again.

 

<?php 

session_start();

if (isset($_SERSSION['name'])) {
  echo "<li class='right active'><a href='account_settings.php' rel='facebox'><span>Welcome back {$_SESSION['name']}!</span></a></li>
<li class='right active'><a href='' rel='facebox'><span>Last login on {$_SESSION['lastlogin']}</span></a></li>";
} else {
echo "<li class='right logout'><a href='create.php' rel='facebox'><span>Create An Account</span></a></li>
<li class='right logout'><a href='login.php' rel='facebox'><span>Login</span></a></li>";
}

?>

 

ps: session_is_registered has LONG been depricated.

Link to comment
Share on other sites

Youve already called echo, no need to do it again.

 

<?php 

session_start();

if (isset($_SERSSION['name'])) {
  echo "<li class='right active'><a href='account_settings.php' rel='facebox'><span>Welcome back {$_SESSION['name']}!</span></a></li>
<li class='right active'><a href='' rel='facebox'><span>Last login on {$_SESSION['lastlogin']}</span></a></li>";
} else {
echo "<li class='right logout'><a href='create.php' rel='facebox'><span>Create An Account</span></a></li>
<li class='right logout'><a href='login.php' rel='facebox'><span>Login</span></a></li>";
}

?>

 

ps: session_is_registered has LONG been depricated.

 

Thankyou very much for your help. :)

All working now; I'm still learning, well, trying to! Haha.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.