0

How to get the email from the database after logging in?

<$
require_once ('database.php'); 
$username = mysql_real_escape_string ($_REQUEST["username"]);
$password = mysql_real_escape_string ($_REQUEST["password"]);
$sql = "SELECT * FROM membertb WHERE username = '" . $username . "' AND password = md5('" . $password . "')";
$result = mysql_query($sql);          
$datarow = mysql_fetch_row($result);
$mailer= mysql_fetch_array($result);
$mail=$mailer['email'];
$code=rand(100000,999999); 
if ($datarow) {  
   require 'phpmailer/PHPMailerAutoload.php';
   $row=$datarow['email'];
   $mail = new \PHPMailer;
   $mail->isSMTP();
   $mail->Host = "smtp.gmail.com";
   $mail->SMTPSecure = "ssl";
   $mail->Port = 465;
   $mail->SMTPAuth = true;
   $mail->Username = '';
   $mail->Password = '
   $mail->setFrom('senaidbacinovic@gmail.com', 'AceLearning');
   $mail->addAddress($mail);
   $mail->Subject = 'SMTP email test';
   $mail->Body = "The code is $result ";
   $mail->send();  
} else{
   $resultStr = header("Location:");  
  echo json_encode($resultStr);
}
?>
paulsm4
  • 114,292
  • 17
  • 138
  • 190
qqq ss
  • 1
  • 1
  • 1
    MD5 is considered broken for security purposes and is not sufficient for password hashing. Use [`password_hash()`](http://us3.php.net/manual/en/function.password-hash.php) and [`password_verify()`](http://us3.php.net/manual/en/function.password-verify.php) instead. – Alex Howansky Feb 06 '19 at 17:11
  • 1
    Also please note that the `mysql_*` functions have been deprecated since v5.5 (Jun 2013) and removed since v7.0 (Dec 2015), and that the `real_escape_string()` functions are not always sufficient to prevent SQL injection. You should use prepared statements with bound parameters, via either [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php). [**This post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) has some good examples. – Alex Howansky Feb 06 '19 at 17:12

0 Answers0