cluce Posted May 18, 2007 Share Posted May 18, 2007 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); ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted May 18, 2007 Share Posted May 18, 2007 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']; Quote Link to comment Share on other sites More sharing options...
cluce Posted May 18, 2007 Author Share Posted May 18, 2007 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); ?> Quote Link to comment Share on other sites More sharing options...
cluce Posted May 18, 2007 Author Share Posted May 18, 2007 I got this working. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.