It's not that difficult, actually. It's daunting for one who doesn't know PHP, but it's still not that bad. If you review your overview of the problem, you'll find that your logic is somewhat flawed. You have
Quote:
quote:
i. username is contained in table(a) pword in table(b)
ii. If the e-mail address exists
a. Search table(b) for the corresponding
record, i.e., the one that has the
same "Id"
b. If there is a value in the password
field in table(b), Combine the information
and send it in an e-mail with the username
and password.to the the address listed in
table(a)
iii. If the e-mail address does not exist,
a. Return to the login page and display
an error message advising users
what to do next.
b. If the e-mail address exists, but there
is no value in the password field,
Return to the login page and display
an error message advising users what
to do next.
|
Well, item iii.b is invalid -- you can't have an "if the email exists" within the scope of "if the email does NOT exist".
All that being said, your script will be SOMEthing like this:
<?php
if (!isset($_POST['email']) || empty($_POST['email']))
{
header("Location: login.php?error=blankemail");
}
$email = $_POST['email'];
$query = "SELECT id FROM a WHERE email = '{$email}'";
$result = mysql_query($query);
// email doesn't exist
if (mysql_num_rows($result) == 0)
{
header("Location: login.php?error=bademail");
}
// should only be one result row
$id = mysql_result($result, 0); //
http://www.php.net/mysql_result
$query = "SELECT password FROM b WHERE id='{$id}'";
$result = mysql_query($query);
// password doesn't exist (how would this happen??)
if (mysql_num_rows($result) == 0)
{
header("Location: login.php?error=nopassword");
}
$password = mysql_result($result, 0);
$message = "Hello,
Your password is: {$password}
Take care,
Your friendly web support staff.
";
mail($email, // To
"Password request", // Subject
$message); // Message body
//
http://www.php.net/mail
header("Location: login.php?error=passwordsent");
?>
I leave it to you to connect to the DB, perform validity/error checking, etc.
I also leave it to you to modify login.php to output the appropriate error/informative messages given the existence and value of $_GET['error'].
Take care,
Nik
http://www.bigaction.org/