forget password can't function...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bb nicole
    New Member
    • Jan 2007
    • 127

    forget password can't function...

    Below is my forget password, why cannot function?? When i click on the submit button, it still remain on the same page and just like i didn't click anything...

    [PHP]<?php
    if($go == "1")
    {
    mysql_connect(" localhost","roo t","");
    mysql_select_db ("ums e-job portal");

    $sql = @mysql_query("S ELECT * FROM company WHERE username='$user name' && emailAdd='$emai l' ");
    if(!$sql)
    {
    echo "The username and email address do not match.";
    exit;
    }
    $query = mysql_query($sq l);
    $fPass = mysql_fetch_arr ay($query);

    $to = "SELECT * FROM company WHERE emailAdd='$emai l' ";
    $subject = "Your Password";
    $body = "SELECT * FROM company WHERE username='$user name' && password='$pass word' ";
    $headers = "From: admin@localhost .com\n";

    mail($to, $subject, $body, $headers);
    echo "Your Password has been sent to $to";
    }
    ?>[/PHP]

    [HTML]<form action="<?= $PHP_SELF ?>" method="post">
    Username: <input type="text" name="username" size="24" border="0"><br>
    E-mail: <input type="text" name="email" size="24" border="0"><br>
    <input type="hidden" name="go" value="1" border="0"><inp ut type="submit" name="submitBut tonName" border="0">
    </form[/HTML]>
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Are these both the same page?

    Comment

    • bb nicole
      New Member
      • Jan 2007
      • 127

      #3
      Originally posted by Motoma
      Are these both the same page?


      Ya... :)
      I have seperate it after this, but it still cannot function, just link to the page got the php code but is blank...

      Thanks...

      Comment

      • steven
        New Member
        • Sep 2006
        • 143

        #4
        Firstly, PHP_SELF should be changed to $_SERVER['PHP_SELF'] and perhaps you could try adding echo statements into your PHP to debug. For example, one just after your if statement, to see if you even reach the condition.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          MySQL databases can not have spaces.
          So if this is really the database you try to connect to it will give you an error.

          [PHP]mysql_select_db ("ums e-job portal");[/PHP]

          Try this to see if it is the error

          [PHP]mysql_select_db ("ums e-job portal") or die(mysql_error );[/PHP]

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Also just noticed this.

            [PHP]<form action="<?= $PHP_SELF ?>"[/PHP]

            Dont know if the <?= is usable in older versions but it wont work in php 5.2
            It should be <?php
            Note. that in PHP 5.2.0 <? is also wrong uless you have the 'short_open_tag ' set to 'on' in your php.ini (default is off)

            And as Steven said it is probbly better to write
            $_SERVER['PHP_SELF'] rather than $PHP_SELF,
            tho both will work on PHP 5

            An you will have to acctually print it so you need to do echo or print

            [PHP]<form action="<?php echo $_SERVER['PHP_SELF']; ?>"[/PHP]

            Comment

            • bb nicole
              New Member
              • Jan 2007
              • 127

              #7
              THANKS Alti and Steven...
              I modify the code ledy but still can't work...
              And i try 2 detect the error by put
              [PHP]<? error_reporting (E_ALL);[/PHP] as Alti told me before, the error message appear as below:
              Notice: Undefined variable: go in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 3
              which line 3 is [PHP]<? if($go == "1") ?>[/PHP]

              And i have put the code:
              [HTML]<input type="hidden" name="go" value="1" border="0"><inp ut type="submit" name="submit" value="Submit" border="0">
              </form>[/HTML]
              at the bottom of the page...

              Is it need to code something as below to define it??
              [PHP]<?
              $go=..........;
              ?>[/PHP]
              BUt i don't know how to code it, can somebody give me some guildeline??? Thanks..

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                Try replacing it with

                [PHP]$_REQUEST['go'][/PHP]

                Also, its always best to close all HTML tags, like so.

                [HTML]<input ...></input>
                or
                <input ... />[/HTML]

                Comment

                • bb nicole
                  New Member
                  • Jan 2007
                  • 127

                  #9
                  Originally posted by Atli
                  Try replacing it with

                  [PHP]$_REQUEST['go'][/PHP]

                  Also, its always best to close all HTML tags, like so.

                  [HTML]<input ...></input>
                  or
                  <input ... />[/HTML]


                  Thanks... I try already, but the error still same as below:
                  Notice: Undefined variable: go in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 3


                  What should i do??? I have no idea how to define the variable... Thanks..

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by bb nicole
                    Thanks... I try already, but the error still same as below:
                    Notice: Undefined variable: go in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 3


                    What should i do??? I have no idea how to define the variable... Thanks..

                    Post the latest version of your code.

                    Comment

                    • bb nicole
                      New Member
                      • Jan 2007
                      • 127

                      #11
                      Originally posted by Motoma
                      Post the latest version of your code.
                      Thanks.. Below is my latest code... All the code is in same page...
                      [PHP]<?php
                      error_reporting (E_ALL);

                      if($_REQUEST['go'] == "1")

                      {
                      mysql_connect(" localhost","roo t","");
                      mysql_select_db ("ums e-job portal") or die(mysql_error );


                      $sql = @mysql_query("S ELECT * FROM company WHERE username='$user name' && emailAdd='$emai l'");
                      if(!$sql)
                      {
                      echo "The username and email address do not match.";
                      exit;
                      }


                      if(!empty($user name)&&!empty($ email)){
                      $query = mysql_query($sq l)
                      or die("Cannot execute query");
                      }

                      $fPass = mysql_fetch_arr ay($query);

                      $to = "SELECT * FROM company WHERE emailAdd='$emai l' ";
                      $subject = "Your Password";
                      $body = "SELECT * FROM company WHERE username='$user name' && password='$pass word' ";
                      $headers = "From: admin@localhost .com\n";

                      mail($to, $subject, $body, $headers);
                      echo "Your Password has been sent to $to";
                      }

                      ?>[/PHP]

                      [HTML]
                      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                      Username: <input type="text" name="username" size="24" border="0"><br>
                      E-mail: <input type="text" name="email" size="24" border="0"><br>
                      <input type="hidden" name="go" value="1" border="0"><inp ut type="submit" name="submit" value="Submit" border="0">
                      </form>[/HTML]

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        Try changing

                        [PHP]<?php

                        error_reporting (E_ALL);



                        if($_REQUEST['go'] == "1") [/PHP]

                        to

                        [PHP]
                        <?php

                        error_reporting (E_ALL);



                        if($_POST['go'] == "1") [/PHP]

                        Comment

                        • Atli
                          Recognized Expert Expert
                          • Nov 2006
                          • 5062

                          #13
                          I tried your code, put it all in one .php file, and once I submitted the form, the unidentified index error dissapears.
                          I see no reason why this code should give you the error after you submit the form.

                          I did however notice this.
                          [PHP]// First query, ok
                          $sql = @mysql_query("S ELECT * FROM company WHERE username='$user name' && emailAdd='$emai l'");
                          if(!$sql)
                          {
                          echo "The username and email address do not match.";
                          exit;
                          }

                          // Second query, not ok
                          if(!empty($user name)&&!empty($ email)){
                          $query = mysql_query($sq l) // <-- running the first query
                          or die("Cannot execute query");
                          }

                          $fPass = mysql_fetch_arr ay($query); // <-- Fetching the second, incorrect query
                          [/PHP]

                          You are trying to run the same query twice, and the second time you'r running the ID number of the first one.

                          You should remove the second one and edit the mysql_fetch_arr ay to use the first one.

                          Comment

                          • bb nicole
                            New Member
                            • Jan 2007
                            • 127

                            #14
                            Originally posted by Motoma
                            Try changing

                            [PHP]<?php

                            error_reporting (E_ALL);



                            if($_REQUEST['go'] == "1") [/PHP]

                            to

                            [PHP]
                            <?php

                            error_reporting (E_ALL);



                            if($_POST['go'] == "1") [/PHP]


                            Emm.. I use as what you said, but din't work...
                            The error shown as below:
                            Notice: Undefined index: go in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 4

                            Thanks... :)

                            Comment

                            • bb nicole
                              New Member
                              • Jan 2007
                              • 127

                              #15
                              Originally posted by Atli
                              I tried your code, put it all in one .php file, and once I submitted the form, the unidentified index error dissapears.
                              I see no reason why this code should give you the error after you submit the form.

                              I did however notice this.
                              [PHP]// First query, ok
                              $sql = @mysql_query("S ELECT * FROM company WHERE username='$user name' && emailAdd='$emai l'");
                              if(!$sql)
                              {
                              echo "The username and email address do not match.";
                              exit;
                              }

                              // Second query, not ok
                              if(!empty($user name)&&!empty($ email)){
                              $query = mysql_query($sq l) // <-- running the first query
                              or die("Cannot execute query");
                              }

                              $fPass = mysql_fetch_arr ay($query); // <-- Fetching the second, incorrect query
                              [/PHP]

                              You are trying to run the same query twice, and the second time you'r running the ID number of the first one.

                              You should remove the second one and edit the mysql_fetch_arr ay to use the first one.


                              Thanks, Alti..I delete the second query and the
                              [PHP]$fPass = mysql_fetch_arr ay($query);[/PHP]
                              to
                              [PHP]$fPass = mysql_fetch_arr ay($sql);[/PHP]
                              but it still go error, same error as below:
                              Notice: Undefined index: go in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 4

                              And after submit the username and email, the error as below...

                              Notice: Undefined variable: email in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 21

                              Notice: Undefined variable: username in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 23

                              Notice: Undefined variable: password in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 23

                              Warning: mail(): "sendmail_f rom" not set in php.ini or custom "From:" header missing in C:\Apache2\Apac he2\htdocs\forg etPassword.php on line 26
                              Your Password has been sent to SELECT * FROM company WHERE emailAdd=''



                              And i think it cannot defined the variable go, but i don't how 2 define it...

                              Comment

                              Working...