Hi I am trying to make a script forgot password so when user enter email in it it will verify that if entered email matches the database email if yes then sends confirmation email to his email address. It was working fine untill I was using mysql but after converting it to mysqli it not working. When user enter email in it it does't send email or even it doesn't echo that email sent or no errors.
Here is my Forgot.php script (UPDATED SCRIPT AGAIN)
<?php
error_reporting(0);
if($_POST['submit']=='Send') {
//keep it inside
$email=$_POST['email'];
$con=mysqli_connect("lovehost","root","123","user");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = mysqli_query($con,"select * from login where user_email='$email'") or die(mysqli_error($con));
$numrows = $query->num_rows();
if ($numrows == 1) {
$code=rand(100,999);
$message='You activation link is: http://bing.fun2pk.com/forgot.php?email=$email&code=$code';
mail($email, "Subject Goes Here", $message);
echo 'Email sent';
} else {
echo 'No user exist with this email id';
}
}
?>
<form action="forgot.php" method="post">
Enter you email ID: <input type="text" name="email">
<input type="submit" name="submit" value="Send">
</form>
I tried to fix this using a test in my website and your codes should be like this even that there are a lot of bugs and your database can easily get 'hacked' by anonymous users still just to show the problem. Forgot.php
This worked after I tested :/
I think u should use mysqli_num_rows ($query) method inside your if condition to check if email exist or not.
for example:
If I see it correctly then
$_GET['ID']
is not set, because you submit the form toforgot.php
without a GET value named ID