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 Quote Link to comment 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 } ?> Quote Link to comment 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> ';} ?> Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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>";} ?> Quote Link to comment 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 } ?> Quote Link to comment 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) Quote Link to comment Share on other sites More sharing options...
AviNahum Posted August 17, 2009 Share Posted August 17, 2009 where is your session_start()? Quote Link to comment 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 Quote Link to comment 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>]"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.