This is a discussion on "Makeing a form displayed or not based on a variable" within the PHP Forum section. This forum, and the thread "Makeing a form displayed or not based on a variable are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Makeing a form displayed or not based on a variable
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Hey i was wondering if someone could help me with my script to make it so that if you have logged in then the login form on the main page disapears and when you log out it is visible?
Here is the code: <?php if(!$_SESSION['name']){ you are logged in.<br> view you profile <a href="Profile.php">here</a><br> or logout <a href="logout.php">here</a>. } else { //This is where i need to make the form invisible } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <style type="text/css"> <!-- body,td,th { font-family: Cooper Black; font-size: 18px; color: #CC0000; } body { background-color: #000000; } a { font-size: 24px; color: #FFFFFF; } a:visited { color: #666666; } a:hover { color: #00FF00; } a:active { color: #CC0000; } .style11 {color: #CC0000} .style12 {font-size: 24px; color: #999999; } .style13 {color: #999999} .ws20 {font-size: 27px;} --> </style></head> <body> <div align="left"></div> //this is the form i need to make invisible when !$_SESSION['name'] is used in the php script at the top <form name="login" method="post" action="Login.php?action=login"> <p align="center">Login</p> <p align="center">Username: <input type="text" name="username"> Password: <input type="password" name="password"> </p> <p align="center"> <input type="submit" name="Submit" value="Login"> </p> <p align="center">Don't have a username? Register <a href="Register.php">here </a></p> </form> Please help me Thanks BRONIC |
|
|
|
|||
|
Re: Makeing a form displayed or not based on a variable
if(isset($_SESSION['logged_in'])){
Put whatever u want to display here when the user is logged in } else { put the logged out content here } **The above assumes your using a session to track the users status. Hope this helped |
|
|||
|
Re: Makeing a form displayed or not based on a variable
Is this what you mean?
<?php if(isset($_SESSION['name'])){ you are logged in.<br> view you profile <a href="Profile.php">here</a><br> or logout <a href="logout.php">here</a> } else { <form name="login" method="post" action="Login.php?action=login"> <p align="center">Login</p> <p align="center">Username: <input type="text" name="username"> Password: <input type="password" name="password"> </p> <p align="center"> <input type="submit" name="Submit" value="Login"> </p> <p align="center">Don't have a username? Register <a href="Register.php">here </a></p> </form> } ?> |
|
|||
|
Re: Makeing a form displayed or not based on a variable
to print anything to the screen.. tables divs.. in fact any html tag use this
Last edited by Accurax; Apr 19th, 2007 at 15:54. |
|
|||
|
Re: Makeing a form displayed or not based on a variable
Never mind i fixed it this morning and it works like this:
<?php session_start(); header("Cache-control: private"); if (!$_SESSION['name']){ print "<form name='login' method='post' action='Login.php?action=login'> <p align='center'>Login</p> <p align='center'>Username: <input type='text' name='username'> Password: <input type='password' name='password'> </p> <p align='center'> <input type='submit' name='Submit' value='Login'> </p> <p align='center'>Don't have a username? Register <a href='Register.php'>here </a></p> </form>"; } else { print "<p align='center'>you are logged in.</p> <p align='center'>view you profile <a href='Profile.php'>here</a></p> <p align='center'>or logout <a href='logout.php'>here</a></p>"; } ?> Thanks for your help though it is greatly appreciated!! -BRONIC |
![]() |
| Tags |
| form variable, visible |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hiding / Showing form fields based on previous form input | John Alexander Hopper | PHP Forum | 1 | Mar 10th, 2008 11:30 |
| form variable within an iframe component of a form | kissfreaque | PHP Forum | 3 | Feb 29th, 2008 13:06 |
| form variable within an iframe component of a form | kissfreaque | JavaScript Forum | 5 | Feb 29th, 2008 11:57 |
| flash based e-mail form | HogDog | Flash & Multimedia Forum | 1 | Dec 24th, 2006 06:18 |
| Setting Mailform Variable Based on Database | rgrimes | Classic ASP | 3 | Aug 12th, 2006 14:52 |