Jump to content

Warning: Cannot modify header information


silverglade

Recommended Posts

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>";
    }

?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>";
    }

?> 

Link to comment
Share on other sites

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>";
    }

?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.