retrieve a lost password
Posted: Wed Feb 09, 2005 5:59 pm
I wonder if anybody can tell me where I’m going wrong with this. As a beginner to PHP I’m very lost but basically I’m trying to retrieve a lost password by having an email address inserted into a form that searches the database and emails this back to the client.
(At the moment I’m just returning this to the browser to keep things simple for testing).
I can manage to get various results but no matter what I try none are satisfactory. There are 3 main things that I need to do. Firstly if the form is left blank it need to have an error showing that there is no match in the database and similarly if an email address is not found I need the same message displayed. Thirdly I then need to return the correct password if the email and password match.
I know the logic but can’t seem to figure it out in the script.
I have tried a few methods such as:
Attempt 1
Attempt 2
And this is a complete code that will retrieve and return a correct email/ password but if I leave the form blank or insert a incorrect address nothing at all happens i.e. no error messages are displayed.
If anyone can help I’d be very grateful as I thought that this should be easy to do but that was my first mistake!
Thanks a mil
(At the moment I’m just returning this to the browser to keep things simple for testing).
I can manage to get various results but no matter what I try none are satisfactory. There are 3 main things that I need to do. Firstly if the form is left blank it need to have an error showing that there is no match in the database and similarly if an email address is not found I need the same message displayed. Thirdly I then need to return the correct password if the email and password match.
I know the logic but can’t seem to figure it out in the script.
I have tried a few methods such as:
Attempt 1
Code: Select all
<?php //if (!empty($_GETї'username']))
$username = $_GETї'username'];
if ($username == 0) {
echo $row_rstGetLostEmailї'password'];
}
else {
echo 'get out of here';
}Code: Select all
if (!empty($_POSTї'username'])){
echo 'sorry there is no match';
}
else {
echo $row_rstGetLostEmailї'password'];
}If anyone can help I’d be very grateful as I thought that this should be easy to do but that was my first mistake!
Thanks a mil
Code: Select all
<?php require_once('Connections/b.php'); ?>
<?php
$colname_rstGetLostEmail = "1";
if (isset($_GETї'username'])) {
$colname_rstGetLostEmail = (get_magic_quotes_gpc()) ? $_GETї'username'] : addslashes($_GETї'username']);
}
mysql_select_db($database_brian, $brian);
$query_rstGetLostEmail = sprintf("SELECT * FROM users WHERE username = '%s'", $colname_rstGetLostEmail);
$rstGetLostEmail = mysql_query($query_rstGetLostEmail, $brian) or die(mysql_error());
$row_rstGetLostEmail = mysql_fetch_assoc($rstGetLostEmail);
$totalRows_rstGetLostEmail = mysql_num_rows($rstGetLostEmail);
?>
<body>
<?php //if (!empty($_GETї'username']))
if (empty($_POSTї'username'])) {
echo $row_rstGetLostEmailї'password'];
}
else {
echo 'sorry there is no match';
}
?>
<form name="form1" method="$_POSTї'username']" action="<?php $_SERVERї'PHP_SELF']?>">
<input type="text" name= "username">
<input type="submit" value="Search For Password">
Retrieve Lost Password
</form>
</body>
<?php
mysql_free_result($rstGetLostEmail);
?>