Jump to content

Recommended Posts

Hi. I'm making a form for users who have forgotten their password. Basically, they type in their username, and then 'checklost.php' puls their 'Secret Question' from the database. They fill in the answer, and if it matches with their chosen answer, they will then have the option to reset their password. Sounds pretty simple, but it won't work!!

 

Here is the main form;

<form name="form1" method="post" action="checklost.php">
					<fieldset>
						<!--[if !IE]>start row<![endif]-->
						<div class="row">
							<label>Username:</label>
							<span class="input_wrapper">
								<input class="text" name="user" type="text" />
							</span>
						</div>
						<!--[if !IE]>end row<![endif]-->
						<!--[if !IE]>start row<![endif]-->
						<!--[if !IE]>end row<![endif]-->
						<!--[if !IE]>start row<![endif]-->
						<!--[if !IE]>end row<![endif]-->
						<!--[if !IE]>start row<![endif]-->
							<div class="row">
								<div class="inputs small_inputs"> <span class="button gray_button unlock_button"><span><span><em>
								  <input name="apdiv" type="submit" />
							    Next Step</em></span></span></span> </div>
							</div>
							<!--[if !IE]>end row<![endif]-->
					</fieldset>
				</form>

 

And this is 'checklost.php';

<?php
ob_start();
$host="localhost";
$username="wowdream_hub";
$password="PASSWORD";
$db_name="wowdream_hub"; 
$tbl_name="members";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$user=$_POST['user'];

$sql="SELECT * FROM $tbl_name WHERE username='$user'";
$result=mysql_query($sql);
$data=mysql_fetch_array($result);
$secretq= $data['serectq'];
$secrera= $data['secreta'];

$count=mysql_num_rows($result);

if($count==1){
session_register("user");
session_register("secretq");
session_register("secreta");

header("location:step2.php");
}
else {
header("location:error.php");
}

ob_end_flush();
?>

 

And this is where their secret question is echoed;

<?PHP 
session_start();
if(!session_is_registered(secretq)){
header("location:index.php");
}
?>
<form name="form1" method="post" action="checklost2.php">
					<fieldset>
						<!--[if !IE]>start row<![endif]-->
						<div class="row">
							<label><? echo $secretq ?>:</label>
							<span class="input_wrapper">
								<input class="text" name="user" type="text" />
							</span>
						</div>
						<!--[if !IE]>end row<![endif]-->
						<!--[if !IE]>start row<![endif]-->
						<!--[if !IE]>end row<![endif]-->
						<!--[if !IE]>start row<![endif]-->
						<!--[if !IE]>end row<![endif]-->
						<!--[if !IE]>start row<![endif]-->
							<div class="row">
								<div class="inputs small_inputs"> <span class="button gray_button unlock_button"><span><span><em>
								  <input name="apdiv" type="submit" />
							    Next Step</em></span></span></span> </div>
							</div>
							<!--[if !IE]>end row<![endif]-->
					</fieldset>
				</form>

 

Can anyone see my problem?

Cheers, Adam.

Link to comment
https://forums.phpfreaks.com/topic/138314-cant-work-out-whats-wrong-with-this/
Share on other sites

Your code appears to be relying on register_globals in order to function correctly. registert_globals has long been depreciated and has been disabled by default for  along time. It is now due to be removed as of PHP6

 

Also when handling settings avoid using functions such as session_register, session_is_registered etc. These are also depreciated. Instead you should use the $_SESSION superglobal variable instead, examples

 

file1.php

<?php
// start the session
session_start();

// create a session variable
$_SESSION['my_var'] = 'hello world';

?>
<a href="file2.php">Next</a>

 

file2.php

<?php
// start the session
session_start();

// check that our session variable 'my_var' exists
if(isset($_SESSION['my_var']))
{
    echo $_SESSION['my_var'];
}
else
{
    echo "the session variable 'my_var' does not exist!";
}

?>

 

You don't need a semi colon if its the last line of code.

 

i just noticed you have

<? echo $secretq ?>

you should have

<? echo $secretq; ?>

 

Really? I didn't know this. Clever :)

*gets back on topic*

What do the errors (from error reporting) say?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.