www.webdeveloper.com
Results 1 to 5 of 5

Thread: Forgotten Password Script

  1. #1
    Join Date
    Feb 2006
    Posts
    3

    Forgotten Password Script

    Hey there.

    I've created an "email my password" script for my site that can be emailed to a user via a simple form. It works fine, with either a "success" or "please try again" phrase that appears depending upon whether a match in the database is made. The problem I have is when NO text is entered into the text field (text field box = userEmail.) When a user then hits submit - the "success" phrase is shown, rather than "please try again". Here's my script... hope someone can help:


    <?php
    //Show If Conditional
    if (@$row_retrievePassword['user_email'] == $_POST['userEmail']) {
    $to = $_POST['userEmail'];
    $from = "From: xyz@abc.com";
    $subject = "Your Password Request";
    etc etc
    $_POST['userEmail'];
    ?>

    Success! Your password has been sent.


    <?php
    //Show If Not Conditional
    } elseif (@$row_retrievePassword['user_email'] != $_POST['userEmail']) {
    ?>

    This address could not be found. Please try again.


    <?php
    } // End
    ?>

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    PHP Code:
    <?php
    //Show If Conditional
    if (@$row_retrievePassword['user_email'] == $_POST['userEmail'] && isset($_POST['userEmail']) {
    $to $_POST['userEmail'];
    $from "From: [email]xyz@abc.com[/email]";
    $subject "Your Password Request";
    etc etc
    $_POST
    ['userEmail'];
    ?>

    Success! Your password has been sent.


    <?php
    //Show If Not Conditional
    } elseif (@$row_retrievePassword['user_email'] != $_POST['userEmail']) {
    ?>

    This address could not be found. Please try again.


    <?php
    // End
    ?>

  3. #3
    Join Date
    Jan 2006
    Location
    London
    Posts
    50
    Instead of:

    isset($_POST['userEmail'])

    you may need to use

    $_POST['userEmail'] != ''

    As although there is no data in the field, it may still be considered as being set.

  4. #4
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    If there is no data the browser wont send the field and therefore it will never be set unless something is in it

  5. #5
    Join Date
    Jan 2006
    Location
    London
    Posts
    50
    Quote Originally Posted by bathurst_guy
    If there is no data the browser wont send the field and therefore it will never be set unless something is in it
    Not sure if you've tested that but the servers I work with will detect all fields within the POSTed form as being set, even if they are blank. This may be browser dependant, but as you can't gaurauntee what your site will be viewed with I would recommend checking for both eventualities.

    PHP Code:
    if (isset($_POST['field']) && $_POST['field'] != '')
    {...} 
    Last edited by Brooksie155; 03-15-2006 at 04:29 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles