i was playing with the code of pset7 and have edited it in such a way that during registration the user is asked to provide his email id and I am saving the email id and the original password that he typed in into a table. Then I have added a forgotten password page link into the login page where the user can type in his email
and if its there in the db then I have used the mail
function to mail him his original password.But on giving my working email id I am getting this error
Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM users WHERE email = 'furrukh@hotmail\.com'' at line 1 in /home/ubuntu/workspace/project/wall/vendor/library50-php-5/CS50/CS50.php on line 352
I have two questions 1. Why am I getting this error and how to solve the issue?
- If I somehow fix this have I implemented the
mail
function correctly and will I receive a mail with my password in it.
The relevant code is as follows
<?php
// configuration
require("../includes/config.php");
// check to see if user came via GET(by clicking a link)
if($_SERVER["REQUEST_METHOD"] == "GET")
{
render("forgotpasswordform.php", ["title" => "Forgotten Password"]);
}
else if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["email"]))
{
apologize("You did not submitted a valid email");
}
//removing the dot with \.
//$email = str_replace(".", "\.", $_POST["email"]);
// check to see if email exsists in the db
$rows = CS50:: query("SELECT FROM users WHERE email = ?", $_POST["email"]);
if ($rows != 1)
{
apologize("The email you entered is not a registered email at the wall");
}
else
{
// mail the user his password
$password = $rows[0]["originalpass"] ;
$mailid = $rows[0]["email"];
$subject = "Your password for The Wall";
$message = "This is a auto generated message plz do not reply to it.\r\n Your password is {$password}";
$message = wordwrap($message, 70, "\r\n");
$header = "From: [email protected]";
mail($mailid, $subject, $message, $header);
redirect("/");
}
}
// Added 4 spaces to include line in code block
?>
EDIT
the answer is very helpful, just one more thing how would I send a link thru php mailer?
$mail->Body =
"Reset your password at http://www.myweb.php?query =".$query;
or do I have to include a <a href>
tag with in $mail ->Body
to display it as a link in the mail?