Forgot Password Using PHP
read me
---------
1.$message="You activation link is:http://www.soengsouy.com/Sign-Up/
.php?email=$email&code=$code";
2. you must change to your localhost.
1.forgotpass.php
<?php
error_reporting(0);
$errors ='';
if($_POST['submit']=='Send')
{
//keep it inside
$email=$_POST['email'];
$password = $_GET['passsword'];
$con=mysqli_connect("Localhost","root","","register_login");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = mysqli_query($con,"SELECT * FROM user_login WHERE email='$email'")
or die(mysqli_error($con));
if (mysqli_num_rows ($query)==1)
{
$code= rand(100,999);
$message="You activation link is:http://www.soengsouy.com/Sign-Up/.php?email=$email&code=$code";
mail($email, "Send Code", $message);
echo 'Email sent';
$query2 = mysqli_query($con,"UPDATE password SET passsword='$password' WHERE email='$email'")
or die(mysqli_error($con));
}
else
{
$errors = '<div class="alert alert-danger" role="alert">Sorry, Your emails does not exists in our record database</div>'
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ForgotPassword</title>
</head>
<body>
<!-- Material form login -->
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-4 mt-5 rounded">
<div class="card">
<h5 class="card-header info-color white-text text-center py-4">
<strong>ForgotPassword</strong>
</h5>
<!--Card content-->
<div class="card-body px-lg-5 pt-0">
<!-- Form -->
<form class="text-center"action="forgotpass.php" method="POST">
<!-- Email -->
<div class="md-form">
<?= $errors?>
<input type="email"name="email" id="email" class="form-control" placeholder="E-mail">
</div>
<!-- Sign in button -->
<button class="btn btn-outline-info btn-roundedbtn-block my-4 waves-effect z-depth-0" type="submit" name="submit" value="Send">Send Code To Mail</button>
<!-- Social login -->
<a href="signin.php">Sing in</a>
<p>or sign in with:</p>
<a href="#"><i class="fa fa-twitter"></i></a>
<a href="#"><i class="fa fa-youtube"></i></a>
<a href="#"><i class="fa fa-linkedin"></i></a>
</form>
<!-- Form -->
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<?php include('server1.php') ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Sign Up</title>
</head>
<body>
<!-- Material form register -->
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-4 mt-3 rounded ">
<div class="card ">
<h5 class="card-header info-color white-text text-center py-4"><strong>New Password</strong>
</h5>
<!--Card content-->
<div class="card-body px-lg-5 pt-0">
<!-- Form -->
<form class="text-center" action="resetpassword.php" method="POST">
<?php include('errors.php'); ?>
<div class="form-row">
<div class="col">
<!-- Password -->
<div class="md-form">
<input type="password" name="password" id="password" class="form-control" placeholder="New Password">
</div>
<!-- Sign up button -->
<button class="btn btn-outline-info btn-rounded btn-block my-4 waves-effect z-depth-0 " type="submit" name="submit"> Sign Up</button>
<!-- Social register -->
<p>or sign up with:</p>
<a href="#"><i class="fa fa-twitter"></i></a>
<a href="#"><i class="fa fa-youtube"></i></a>
<a href="#"><i class="fa fa-linkedin"></i></a>
<hr>
<!-- Terms of service -->
<em>Already have account? <a href="signin.php">Sign in</a></em>
</form>
<!-- Form -->
</div>
</div>
<!-- Material form register -->
</div>
</div>
</div>
</body>
</html>
3.server1.php
<?php
$errors = array();
if(isset($_POST['submit']))
{
$db=mysqli_connect("Localhost","root","","register_login");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// receive all input values from the form
$password = mysqli_real_escape_string($db, $_POST['password']);
if (empty($password))
{
array_push($errors, '<div class="alert alert-danger" role="alert">Password is required</div>');
}
$query = mysqli_query($db,"SELECT * FROM user_login WHERE `user_login`.`id` = 1")
or die(mysqli_error($db));
if (mysqli_num_rows ($query)==1)
{
$password = md5($password);
$query3 = mysqli_query($db,"UPDATE user_login SET `password`='$password' WHERE `user_login`.`id` = 1")
or die(mysqli_error($db));
echo '<div class="text-center"><div class="alertalert-success" role="alert">Password Changed </div> </div>';
}
}
?>
2 Comments
Hi bro
ReplyDeleteI changed my location but show me again this msg in page:
Email sentTable 'register_login.password' doesn't exist
how to solve that ?
g
ReplyDeleteCAN FEEDBACK
Emoji