user3056818 user3056818 - 1 year ago 254
MySQL Question

Forgot Password script PHP mysqli

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)

if($_POST['submit']=='Send') {
//keep it inside

// 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) {
$message='You activation link is:$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">

Answer Source

I think u should use mysqli_num_rows ($query) method inside your if condition to check if email exist or not.

for example:

if (mysqli_num_rows ($query)==1)
//your mail method
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download