Jump to content

If Else = Show Hide?


Recommended Posts

Hi there.I have been trying to get a login form to show if not logged in and hide if you are displaying instead a greeting. Everyone does it , should be easy. LOL Ok I am a newbie for sure here.I have some code that works on a registration form. After you submit the form goes away and a 'Thank You' appears in its place.I copied that and changed out the form line by line making sure the 'show if' grey tag stayed on the text to display.Well it still doesn't work. I have been re coding this for more than a week now with no luck.The difference in the one that works (registration) and the one that doesn't is a tag that says <mm_hiddenregion> and only shows up on the bottom of my dreamweaver window when I click on the Thank You text.I cannot find any reference in the dreamweaver documentation or searching the forums. PLease help me achieve this show hide login feature!Here is what I have for code that works, registration:

<?php // Connects to your Database mysql_connect("h", "w", "p") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); //This code runs if the form has been submittedif (isset($_POST['submit'])) { //This makes sure they did not leave any fields blankif (!$_POST['username'] | !$_POST['password'] | !$_POST['password2'] | !$_POST['email'] | !$_POST['zip']) {die('You did not complete all of the required fields');}// checks if the username is in useif (!get_magic_quotes_gpc()) {$_POST['username'] = addslashes($_POST['username']);}$usercheck = $_POST['username'];$check = mysql_query("SELECT username FROM members WHERE username = '$usercheck'") or die(mysql_error());$check2 = mysql_num_rows($check);//if the name exists it gives an errorif ($check2 != 0) {die('Sorry, the username '.$_POST['username'].' is already in use.');}// this makes sure both passwords entered matchif ($_POST['password'] != $_POST['password2']) {die('Your passwords did not match. ');}// here we encrypt the password and add slashes if needed$_POST['password'] = md5($_POST['password']);if (!get_magic_quotes_gpc()) {$_POST['password'] = addslashes($_POST['password']);$_POST['username'] = addslashes($_POST['username']);$_POST['email'] = addslashes($_POST['email']);$_POST['zip'] = addslashes($_POST['zip']);}// table name $tbl_name=members;// Random confirmation code $confirm_code=md5(uniqid(rand()));// values sent from form $name=$_POST['username'];$email=$_POST['email'];$password=$_POST['password'];$zip=$_POST['zip'];// Insert data into database $sql="INSERT INTO $tbl_name(confirm_code, username, email, password, zip)VALUES('$confirm_code', '$name', '$email', '$password', '$zip')";$result=mysql_query($sql);// if suceesfully inserted data into database, send confirmation link to email if($result){// ---------------- SEND MAIL FORM ----------------// send e-mail to ...$to=$email;// Your subject$subject="Your confirmation link.";// From$header="from: blank.com <noreply@blank.com>";// Your message$message="Your Comfirmation link \r\n";$message.="Click on this link to activate your account \r\n";$message.="http://www.blank.com/U/c.php?passkey=$confirm_code";// send email$sentmail = mail($to,$subject,$message,$header);}// if not found else {echo "Your email is not in our database";}// if your email succesfully sentif($sentmail){echo "";}else {echo "Cannot send Confirmation link to your e-mail address";}?><h1 align="center">Thank You!</h1><p align="center">Please check your email.<br />  Activate your registration now.</a></p><?php } else {	?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><table border="0" align="center"><tr><td class="style1">Username:</td><td><input type="text" name="username" maxlength="60"></td></tr><tr><td class="style1">Password:</td><td><input type="password" name="password" maxlength="10"></td></tr><tr><td class="style1">Confirm Password:</td><td><input type="password" name="password2" maxlength="10"></td></tr><tr>  <td class="style1">E-mail:</td>  <td><input type="text" name="email" maxlength="60"></td></tr><tr>  <td class="style1">Zip</td>  <td><input type="text" name="zip" maxlength="5"></td></tr><tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table></form><p>  <?php}?>

Here is what isn't working for login:

	<?php 	// Connects to your Database 		mysql_connect("h", "w", "p") or die(mysql_error()); 		mysql_select_db("db") or die(mysql_error()); 	//Checks if there is a login cookie		if(isset($_COOKIE['ID_my_site']))	//if there is, it logs you in and directes you to the members page		{ 			$username = $_COOKIE['ID_my_site']; 			$pass = $_COOKIE['Key_my_site'];			$check = mysql_query("SELECT * FROM table WHERE username = '$username'")or die(mysql_error());				while($info = mysql_fetch_array( $check )) 				{					if ($pass != $info['password']) 					{					}					else					{						header("Location: /U/m.php");					}				}		}		else		{						//This code runs if the form has been submitted			if (isset($_POST['submit'])) 			{ 				//This makes sure they did not leave any fields blank				// makes sure they filled it in				if(!$_POST['username'] | !$_POST['password']) 				{					die('You did not fill in a required field.');				}				// checks it against the database				if (!get_magic_quotes_gpc()) 				{					$_POST['email'] = addslashes($_POST['email']);				}					$check = mysql_query("SELECT * FROM members WHERE username = '".$_POST['username']."'")or die(mysql_error());					$check2 = mysql_num_rows($check);					if ($check2 == 0) 					{						die('That user does not exist in our database. <a href=r.php>Click Here to Register</a>');					}		while($info = mysql_fetch_array( $check )) 				{					$_POST['password'] = stripslashes($_POST['password']);					$info['password'] = stripslashes($info['password']);					$_POST['password'] = md5($_POST['password']);					//gives error if the password is wrong					if ($_POST['pass'] != $info['password']) 					{						die('Incorrect password, please try again.');					}						else 						{ 							// if login is ok then we add a cookie 							$_POST['username'] = stripslashes($_POST['username']); 							$hour = time() + 3600; 							setcookie(ID_my_site, $_POST['username'], $hour); 							setcookie(Key_my_site, $_POST['password'], $hour);								//then redirect them to the members area 							header("Location: /U/m.php"); 						} 				} 		} else {	?><h6 align="center"> Welcome Username. </h6><?php } ?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><table border="0" align="left"><tr><td class="style44">Username:</td>  <td class="style44"><input type="text" name="username" maxlength="60" /></td>  <td><span class="style44">Password:</span></td>  <td><input type="password" name="password" maxlength="10" /></td>  <td><input type="submit" name="button2" id="button2" value="Login" /></td></tr> </table></form>

I sure would appreciate some direction.Thanks!

Link to comment
Share on other sites

Check here, this might be an easier example to start with:http://w3schools.invisionzone.com/index.php?showtopic=12509
Thanks! I am studying it now.I looked at it and didn't see anything that would make the form itself invisible if a session was set though.I think maybe I am not sure what that would look like. I thought it would be an if isset. Is it the input type being hidden that does it?I am trying to understand what actually determines the visibility of the form vs the greeting.Sorry if it seems a stupid question.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...