/    Sign up×
Community /Pin to ProfileBookmark

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: [email][email protected][/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
?>

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMar 14.2006 — [code=php]<?php
//Show If Conditional
if (@$row_retrievePassword['user_email'] == $_POST['userEmail'] && isset($_POST['userEmail']) {
$to = $_POST['userEmail'];
$from = "From: [email][email protected][/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
?>[/code]
Copy linkTweet thisAlerts:
@Brooksie155Mar 14.2006 — Instead of:

[COLOR=Green]isset([/COLOR][COLOR=Blue]$_POST[/COLOR][COLOR=Green][[/COLOR][COLOR=Red]'userEmail'[/COLOR][COLOR=Green]])[/COLOR]

you may need to use

[COLOR=Blue]$_POST[/COLOR][COLOR=Green][[/COLOR][COLOR=Red]'userEmail'[/COLOR][COLOR=Green]][/COLOR] [COLOR=Green]!=[/COLOR] [COLOR=Red]'' [/COLOR]

As although there is no data in the field, it may still be considered as being set.
Copy linkTweet thisAlerts:
@bathurst_guyMar 15.2006 — If there is no data the browser wont send the field and therefore it will never be set unless something is in it
Copy linkTweet thisAlerts:
@Brooksie155Mar 15.2006 — If there is no data the browser wont send the field and therefore it will never be set unless something is in it[/QUOTE]

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.

[code=php]
if (isset($_POST['field']) && $_POST['field'] != '')
{...}
[/code]
×

Success!

Help @mojobullfrog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...