Jump to content

[SOLVED] matching words from post and query


contra10

Recommended Posts

i'm trying to check if my user has entered the same answer as the answer for security question

 

<?php
if (isset($_POST['submit'])) { 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());

//This makes sure they did not leave any fields blank
if (!$_POST['a'] | !$_POST['pass'] | !$_POST['pass2']) {
die('You did not complete all of the required fields');
}	

// this makes sure both passwords entered match
if ($_POST['a'] != $secreta) {
die("Your answer did not match. Please <a href='http://localhost/validation/renew.php?id=$ida'>try again! </a> ");
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = encrypt($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

$pass = mysql_real_escape_string($_POST['pass']);

// now we insert it into the database
$insert = "UPDATE `users` SET `password` = '$pass' WHERE `username`='$username'";
$add_update = mysql_query($insert);
?>
You can now <a href="http://localhost/">login</a>
<?php
}
else
{
?>
You are almost finish renewing your password<br>



	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		Please answer your question?<br><?php echo "$secretq $secreta";?><br>
Answer:<br>
<input type="a" name="a" maxlength="60" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"><br>

Username:<br>
<input type="text" name="username" maxlength="60" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"><br>

New Password:<br>
<input type="password" name="pass" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"><br>

Confirm Password:<br>
<input type="password" name="pass2" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"><br>
<input type="submit" name="submit" value="Update"/>
</form>
<?php
}
?>

 

i keep getting the die statement at this point

<>php
// this makes sure both passwords entered match
if ($_POST['a'] != $secreta) {
die("Your answer did not match. Please <a href='http://localhost/validation/renew.php?id=$ida'>try again! </a> ");
}
?>

but i did the query and its getting answer and what i enter in the form is the same

You might need to put quotations around your variable in that if statement.

 

if ($_POST['a'] != "$secreta")
{
    die("Your answer did not match. Please <a href='http://localhost/validation/renew.php?id=$ida'>try again! </a> ");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.