1 Replies - 564 Views - Last Post: 24 December 2012 - 04:19 AM Rate Topic: -----

#1 irsilly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-May 12

Reset password form not showing up

Posted 23 December 2012 - 10:46 PM

Hello,

I am making a forgot password page for my login system and my form is not showing up. I checked everything and can't seem to find the mistake. I'm sure its a stupid little one but can't seem to find it. Can anybody help? Code below.

Thanks.

<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>
<!DOCTYPE html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Member System - Login</title>
</head>
<body>
<?php
	
	if(!$username && !userid){
	
		if($_POST['resetbtn']){
		
		}
		
		echo "<form action='./forgotpass.php'>
		<table>
		<tr>
			<td>Username:</td>
			<td><input type='text' name='user' /></td>
		</tr>
		<tr>
			<td>Email:</td>
			<td><input type='text' name='email' /></td>
		</tr>
		<tr>
			<td></td>
			<td><input type='submit' name='resetbtn' value='Reset Password' /></td>
		</tr>
		</table>
		</form>";
	
	}
	else
		echo "Please logout to view this page.";
	
?>
</body>
</html>


Also, I forgot to mention, that it is showing my 'else' statement when I reload my page meaning its just showing me a message of "Please logout to view this page"

Is This A Good Question/Topic? 0
  • +

Replies To: Reset password form not showing up

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

Re: Reset password form not showing up

Posted 24 December 2012 - 04:19 AM

Hey.

Look at the second condition: !userid. You are missing the $ in front of the variable, which means that PHP is assuming it was meant to be the string "userid", which will never evaluate as false. And thanks to your error_reporting call at the top of your page, where you tell it to hide notices, the notice PHP would print to let you know about this never shows.

You should always develop code with error reporting fully enabled, so that you see any and all errors and notices, and then deal with them. Hiding notices instead of fixing them is just asking for trouble. - Presumably you do it because of the way you handle the session variables: copying them to variables without making sure they exist, thus causing undefined index notices, and then checking the value of the variables. That is not a good way to do that. Instead, you should be using functions like empty() or isset() to check the session variables.

Instead of doing this:
$var1 = $_SESSION["var1"];
$var2 = $_SESSION["var2"];
if (!$var1 && !$var2) {

}


Do this:
if(!empty($_SESSION["var1"]) && !empty($_SESSION["var2"])) {

}


Now you can enable the warnings again, so you'll be able to see other warnings that you may not be expecting, like the one I mentioned before.


By the way, I moved this thread to the PHP forum. This isn't really a problem with the HTML or CSS.

This post has been edited by Atli: 24 December 2012 - 04:21 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1