Makeing a form displayed or not based on a variable

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 19th, 2007, 04:23
Junior Member
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to BRONIC
Unhappy Makeing a form displayed or not based on a variable

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

Reply With Quote

  #2 (permalink)  
Old Apr 19th, 2007, 09:37
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #3 (permalink)  
Old Apr 19th, 2007, 11:40
Junior Member
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to BRONIC
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>
}
?>
Reply With Quote
  #4 (permalink)  
Old Apr 19th, 2007, 13:44
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Makeing a form displayed or not based on a variable

Quote:
Originally Posted by BRONIC View Post
Is this what you mean?

<?php
if(isset($_SESSION['name'])){
you are logged in.<br>
First thing - you need to get the matter inside {} in echo/print format.

Headed your way: Parse error: syntax error, unexpected T_STRING
Reply With Quote
  #5 (permalink)  
Old Apr 19th, 2007, 15:52
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
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

Code: Select all
<?php
echo "
tags and other stuff here
";
?>
oh... and if you need to use "" inside the echo statement you need to escape them as follows:

Code: Select all
<?php
echo "<a href=\"url\">Text to be displayed</a>
";
?>

Last edited by Accurax; Apr 19th, 2007 at 15:54.
Reply With Quote
  #6 (permalink)  
Old Apr 20th, 2007, 04:00
Junior Member
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to BRONIC
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

Reply With Quote
Reply

Tags
form variable, visible

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 11:31.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43