silverglade Posted January 27, 2010 Share Posted January 27, 2010 hi, i get the following error when i run my script. after i click the submit button . any help greatly appreciated. Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/oddnerdrum.info/passrecovery7.php:40) in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/oddnerdrum.info/passrecovery7.php on line 49 here is my code <?php include("connect1.php"); ini_set('display_errors', 1); error_reporting(E_ALL); // GREAT SNIPPET FOR DEBUGGING OUTPUTS ERRORS TO SCREEN */ if (isset($_POST['email']) && isset($_POST['Password']) && isset($_POST['Confirm'])) { // Declare Variables $email = mysql_real_escape_string($_POST['email']); $Password = mysql_real_escape_string($_POST['Password']); $Confirm = mysql_real_escape_string($_POST['Confirm']); // Encrypt passwords with md5 encryption $Password = md5($Password); $Confirm = md5($Confirm); if($Password != $Confirm) { echo "The two passwords did not match"; echo "Please enter your email: <form action=\" \" method=\"POST\"> <input type=\email\" name=\"email\"><br> <br> <br><br><br>Please enter your new password: <input type=\"password\" name=\"Password\"><br> <br> Please Confirm that Password: <br><br /> <input type=\"password\" name=\"Confirm\"><br> <br><input type=\"submit\" value=\"Set Password\"</form>"; exit; } // Check if the email already exists in database $query = "SELECT * FROM members WHERE Email = '$email' "; $results = mysql_num_rows(mysql_query($query)); echo $results; if ($results > 0) { // Insert information to the database mysql_query("UPDATE members SET Password='$Password' WHERE Email='$email'"); //Send them to login header("Location:http://oddnerdrum.info/success.html"); } else { echo "<br>email does already exist in the database<br>"; } } else { // Displaying Forms echo "Please enter your email: <form action=\" \" method=\"POST\"> <input type=\"text\" name=\"email\"><br> <br> <br><br>Please enter your password:<br> <input type=\"password\" name=\"Password\"><br> <br> Please Confirm that Password: <br><br /> <input type=\"password\" name=\"Confirm\"><br> <br><input type=\"submit\" value=\"Set Password\"></form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189951-warning-cannot-modify-header-information/ Share on other sites More sharing options...
teamatomic Posted January 27, 2010 Share Posted January 27, 2010 Switch around your logic. You cant use a header ~after~ you have output cause output causes php to automatically send headers echo $results;<<<< output if ($results > 0) { // Insert information to the database mysql_query("UPDATE members SET Password='$Password' WHERE Email='$email'"); //Send them to login header("Location:http://oddnerdrum.info/success.html");<<<header after output HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189951-warning-cannot-modify-header-information/#findComment-1002236 Share on other sites More sharing options...
silverglade Posted January 27, 2010 Author Share Posted January 27, 2010 great thanks. it worked great, but i made a small change to my text, and now i get the same error message. one last jolt of help GREATLY appreciated as im almost done with this script that took me all day. thanks. derek Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/oddnerdrum.info/passrecovery7.php:1) in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/oddnerdrum.info/passrecovery7.php on line 49 here is the latest code <title>Password reset page</title><?php include("connect1.php"); ini_set('display_errors', 1); error_reporting(E_ALL); // GREAT SNIPPET FOR DEBUGGING OUTPUTS ERRORS TO SCREEN */ if (isset($_POST['email']) && isset($_POST['Password']) && isset($_POST['Confirm'])) { // Declare Variables $email = mysql_real_escape_string($_POST['email']); $Password = mysql_real_escape_string($_POST['Password']); $Confirm = mysql_real_escape_string($_POST['Confirm']); // Encrypt passwords with md5 encryption $Password = md5($Password); $Confirm = md5($Confirm); if($Password != $Confirm) { echo "<br>The two passwords did not match<br>"; echo "Please enter your email: <form action=\" \" method=\"POST\"> <input type=\email\" name=\"email\"><br> <br> <br><br><br>Please enter your new password:<br> <input type=\"password\" name=\"Password\"><br> <br> Please Confirm that Password:<br> <br><br /> <input type=\"password\" name=\"Confirm\"><br> <br><input type=\"submit\" value=\"Set Password\"</form>"; exit; } // Check if the email already exists in database $query = "SELECT * FROM members WHERE Email = '$email' "; $results = mysql_num_rows(mysql_query($query)); if ($results > 0) { // Insert information to the database mysql_query("UPDATE members SET Password='$Password' WHERE Email='$email'"); //Send them to login header("Location:success.html"); } else { echo "<br>That email does not exist in the database<br>"; } } else { // Displaying Forms echo "Please enter your email: <form action=\" \" method=\"POST\"> <input type=\"text\" name=\"email\"><br> <br> <br><br>Please enter your password:<br> <input type=\"password\" name=\"Password\"><br> <br> Please Confirm that Password:<br> <br><br /> <input type=\"password\" name=\"Confirm\"><br> <br><input type=\"submit\" value=\"Set Password\"></form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189951-warning-cannot-modify-header-information/#findComment-1002241 Share on other sites More sharing options...
silverglade Posted January 27, 2010 Author Share Posted January 27, 2010 DUH!! HAHA i tried to add a title to the page and dreamweaver put it above the php code causing the error. FINALLY thanks to you i have a FINISHED PASSWORD RESET SCRIPT! HAHAHAAHAH . it took me all freakin day and its DONE. BUM BUM DUM!!!!!! here it is <?php include("connect1.php"); ini_set('display_errors', 1); error_reporting(E_ALL); // GREAT SNIPPET FOR DEBUGGING OUTPUTS ERRORS TO SCREEN */ if (isset($_POST['email']) && isset($_POST['Password']) && isset($_POST['Confirm'])) { // Declare Variables $email = mysql_real_escape_string($_POST['email']); $Password = mysql_real_escape_string($_POST['Password']); $Confirm = mysql_real_escape_string($_POST['Confirm']); // Encrypt passwords with md5 encryption $Password = md5($Password); $Confirm = md5($Confirm); if($Password != $Confirm) { echo "<br>The two passwords did not match<br>"; echo "Please enter your email: <form action=\" \" method=\"POST\"> <input type=\email\" name=\"email\"><br> <br> <br><br><br>Please enter your new password:<br> <input type=\"password\" name=\"Password\"><br> <br> Please Confirm that Password:<br> <br><br /> <input type=\"password\" name=\"Confirm\"><br> <br><input type=\"submit\" value=\"Set Password\"</form>"; exit; } // Check if the email already exists in database $query = "SELECT * FROM members WHERE Email = '$email' "; $results = mysql_num_rows(mysql_query($query)); if ($results > 0) { // Insert information to the database mysql_query("UPDATE members SET Password='$Password' WHERE Email='$email'"); //Send them to login header("Location:success.html"); } else { echo "<br>That email does not exist in the database<br>"; } } else { // Displaying Forms echo "Please enter your email: <form action=\" \" method=\"POST\"> <input type=\"text\" name=\"email\"><br> <br> <br><br>Please enter your password:<br> <input type=\"password\" name=\"Password\"><br> <br> Please Confirm that Password:<br> <br><br /> <input type=\"password\" name=\"Confirm\"><br> <br><input type=\"submit\" value=\"Set Password\"></form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189951-warning-cannot-modify-header-information/#findComment-1002247 Share on other sites More sharing options...
oni-kun Posted January 27, 2010 Share Posted January 27, 2010 Nice. If need be remember, you can use ob_start to send a header after pushing content, if need be. Quote Link to comment https://forums.phpfreaks.com/topic/189951-warning-cannot-modify-header-information/#findComment-1002254 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.