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
https://forums.phpfreaks.com/topic/145707-solved-code-not-working/
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

<?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..)

<?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"

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.

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.