chanfuterboy Posted August 17, 2009 Share Posted August 17, 2009 hi, I just want to echo Home | Profile but i have problem to put it, can someone help me out. <?php if($_SESSION['userid']) {echo "Welcome, ".$_SESSION['username']. echo <a href="http://home.php">home</a> "[<a href='logout.php'>Logout</a>]";} else{?> <form name='login' method='POST' onsubmit="loginfn(this);" action="javascript://"> <label>Username:</label> <input type='text' name='username' value=''/> <label>Password:</label> <input type='password' name='password' value=''/> <input type='submit' value='Login'/> (<a href='javascript:forgotPassword()'>Forgot Password</a>) </form> <?php } ?> The hyperlink need to come before the welcome username Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/ Share on other sites More sharing options...
AviNahum Posted August 17, 2009 Share Posted August 17, 2009 try this: <?php if($_SESSION['userid']) { echo "Welcome, ".$_SESSION['username']; echo "<a href="http://home.php">home</a> [<a href='logout.php'>Logout</a>]"; } else { ?> <form name='login' method='POST' onsubmit="loginfn(this);" action="javascript://"> <label>Username:</label> <input type='text' name='username' value=''/> <label>Password:</label> <input type='password' name='password' value=''/> <input type='submit' value='Login'/> (<a href='javascript:forgotPassword()'>Forgot Password</a>) </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900209 Share on other sites More sharing options...
bmdsherman Posted August 17, 2009 Share Posted August 17, 2009 In the file that checks the username and password register "logged_in" as "1" <?php if($_SESSION['logged_in'] == 1){ echo "Welcome, ".$_SESSION['username']. echo <a href="http://home.php">home</a> "[<a href='logout.php'>Logout</a>]";} else{ echo ' <form name="login" method="POST" onsubmit="loginfn(this);" action="javascript://"> <label>Username:</label> <input type='text' name='username' value=''/> <label>Password:</label> <input type="password" name="password" value=''/> <input type="submit" value="Login"/> (<a href="javascript:forgotPassword()">Forgot Password</a>) </form> ';} ?> Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900212 Share on other sites More sharing options...
chanfuterboy Posted August 17, 2009 Author Share Posted August 17, 2009 nop, 1 has error and the other does not pickup. if you see the script that i post, you remove the echo of homepage it pickup good but as i put the hyperlink it goes Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900221 Share on other sites More sharing options...
AviNahum Posted August 17, 2009 Share Posted August 17, 2009 i think i not really understend your probelm... when you run this script, what the output u get? Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900226 Share on other sites More sharing options...
bmdsherman Posted August 17, 2009 Share Posted August 17, 2009 What is the error message? Here is the exact script I use on my site. <?php $name=$_SESSION['username']?> <?php if ($_SESSION['logged_in'] == 0){include "login.php";}else{echo"Welcome back $name! <br><a href=my_profile.php>My Profile</a><br><a href=logout.php>Log Out</a>";} ?> Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900227 Share on other sites More sharing options...
chanfuterboy Posted August 17, 2009 Author Share Posted August 17, 2009 hi, the error was " " on the hyperlink, but in this code below, it keep comming after the welcome, it need to be, before the welcome <?php if($_SESSION['userid']) { echo "Welcome, ".$_SESSION['username']; echo "<a href='http://home.php'>home</a> [<a href='logout.php'>Logout</a>]"; } else { ?> <form name='login' method='POST' onsubmit="loginfn(this);" action="javascript://"> <label>Username:</label> <input type='text' name='username' value=''/> <label>Password:</label> <input type='password' name='password' value=''/> <input type='submit' value='Login'/> (<a href='javascript:forgotPassword()'>Forgot Password</a>) </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900238 Share on other sites More sharing options...
bmdsherman Posted August 17, 2009 Share Posted August 17, 2009 Your problem is in the if($_SESSION['userid']), That is the equivalent of saying "if raining I will not go out side, if not I will go out side" you need to say "if ITS raining I will not go out side, if not I will go outside". Try this: if($_SESSION['userid'] != 0) Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900241 Share on other sites More sharing options...
AviNahum Posted August 17, 2009 Share Posted August 17, 2009 where is your session_start()? Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900243 Share on other sites More sharing options...
chanfuterboy Posted August 17, 2009 Author Share Posted August 17, 2009 hi, my problem is this two lines { echo "[<a href='http://home.php'>home</a>]" echo "Welcome, ".$_SESSION['username' "[<a href='logout.php'>Logout</a>]" } Home need to come first then welcome username then logout. Not it is a error, can someone help me out i mistaken something Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900327 Share on other sites More sharing options...
bmdsherman Posted August 17, 2009 Share Posted August 17, 2009 Try this: { echo "[<a href='http://home.php'>home</a>]"; echo "Welcome, ".$_SESSION['username' "[<a href='logout.php'>Logout</a>]"; } Link to comment https://forums.phpfreaks.com/topic/170686-solved-basic-help-with-hyperlink/#findComment-900481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.