Jump to content

[SOLVED] forgot password form that submits their account info but gets error warnings


cluce

Recommended Posts

I am trying to do a forgot password page that will email the person his username and password based on the email submitted. Here is the errors I am getting...

Warning: mail() expects parameter 3 to be string, object given in C:\wamp\www\email_info.php on line 26

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\email_info.php:26) in C:\wamp\www\email_info.php on line 28

 

I think it something to do with converting the $res - $body but I am not sure?

 

Can someone tell me whats wrong?

 

here is the code I am use......

<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

//connects to database
$mysqli = @mysqli_connect("localhost", "root", "", "test");

//check to see if email exists in database/table
$usercheck = @strip_tags(trim($_POST['email']));
$check = @mysqli_query($mysqli,"SELECT email FROM auth_users WHERE email = '$usercheck' LIMIT 1"); 
$check2= @mysqli_num_rows($check);

//if the email does not exist, it gives an error
if ($check2 != 0) {
    //echo ("email exists");

    //create and issue the query
    $sql = "SELECT username, password FROM auth_users WHERE email = '".$_POST["email"]."' LIMIT 1";
    $res = @mysqli_query($mysqli, $sql);
    	
    $to = $_POST["email"];
$subject = "Account Information";
$body = $res;
mail ($to, $subject, $body);

header("Location: http:mydomain.com/Account_information.html");

}else{
    $_SESSION['emailExists'] = "<font color='red'>The email"." ".$_POST['email']." "."does not exist in our database.<br>You may register for free by filling out the online registration form.</font>";	
header ("Location: forgot_password.php");
}
mysqli_close($mysqli);
?>

You are mailing the resource of the query, you are not grabbing the data in anyway. Try this:

 

<?php
$res = mysqli_query($mysqli, $sql); // just don't use the @ supporesor bad programming
$bodyArr = mysqli_fetch_array($mysqli, $res);
$body = "Username: " . $bodyArr['username'] . "\nPassword: " . $bodyArr['password'];

 

OK I added those lines but now I get these......

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C:\wamp\www\email_info.php on line 22

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\email_info.php:22) in C:\wamp\www\email_info.php on line 30

<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

//connects to database
$mysqli = @mysqli_connect("localhost", "root", "", "test");

//check to see if email exists in database/table
$usercheck = @strip_tags(trim($_POST['email']));
$check = @mysqli_query($mysqli,"SELECT email FROM auth_users WHERE email = '$usercheck' LIMIT 1"); 
$check2= @mysqli_num_rows($check);

//if the email does not exist, it gives an error
if ($check2 != 0) {
    //echo ("email exists");

    //create and issue the query
    $sql = "SELECT username, password FROM auth_users WHERE email = '".$_POST["email"]."' LIMIT 1";
    $res = mysqli_query($mysqli, $sql); 
$bodyArr = mysqli_fetch_array($mysqli, $sql);
    	
    $to = $_POST["email"];
$subject = "Account Information";
    $body = "Username: " . $bodyArr['username'] . "\nPassword: " . $bodyArr['password'];

mail ($to, $subject, $body);

header("Location: http:company.com/Account_information.html");

}else{
    $_SESSION['emailExists'] = "<font color='red'>The email"." ".$_POST['email']." "."does not exist in our database.<br>You may register for free by filling out the online registration form.</font>";	
header ("Location: forgot_password.php");
}
mysqli_close($mysqli);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.