quasiman Posted August 23, 2012 Share Posted August 23, 2012 Can someone take a look at this and see if there's anything wrong with it? I'm just not seeing a problem, but it gives the error below everytime! //Lost password if (isset($_POST['lostEmail']) && isset($_POST['lostSubmit'])) { $lostEmail = trim($_POST['lostEmail']); if (!filter_var($lostEmail, FILTER_VALIDATE_EMAIL)) $errors['invalidEmail'] = 'Your email address is invalid.'; $query = 'SELECT * FROM users WHERE email = "' . mysql_real_escape_string($lostEmail) . '" LIMIT 1'; $result = mysql_query($query); if (mysql_num_rows($result) <> 1) $errors['noEmail'] = 'This email address does not exist.'; // Probably this if statement.... if (!errors) { $newPassword = "newtestpassword"; $subject = "Lost Password Request"; $txt = "Someone (hopefully you) requested a new password on your hehalf \r \n Login: " . $lostEmail . "\n Password: " . $newPassword . " \r \n Thank you!"; $headers = "From: [email protected]"; if (mail($lostEmail, $subject, $txt, $headers)) { $success['passwordSent'] = "Mail sent successfully"; } else { $errors['passwordSent'] = "Mail failed to send"; } } else { echo "failed<br>"; echo $lostEmail . $subject . $txt . $headers . "<br>"; } } ?> <form class="box400" name="lostPassword" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <h2>Lost Password</h2> <?php if ($errors['invalidEmail']) print '<div class="invalid">' . $errors['invalidEmail'] . '</div>'; ?> <?php if ($errors['noEmail']) print '<div class="invalid">' . $errors['noEmail'] . '</div>'; ?> <label for="lostEmail">Email Address</label> <input type="text" name="lostEmail" value="" /> <input type="submit" name="lostSubmit" value="Lost Password" /> <?php if ($success['passwordSent']) print '<div class="valid">' . $success['passwordSent'] . '</div>'; ?> <?php if ($errors['passwordSent']) print '<div class="invalid">' . $errors['passwordSent'] . '</div>'; ?> </form> The only return I get is: failed [email protected] Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/ Share on other sites More sharing options...
Pikachu2000 Posted August 23, 2012 Share Posted August 23, 2012 $errors is returning TRUE. There are only 2 reasons in that code for that to happen. What have you done to troubleshoot it? I'd start by seeing exactly what is in the $errors array. Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371952 Share on other sites More sharing options...
quasiman Posted August 23, 2012 Author Share Posted August 23, 2012 I tried adding print_r($errors), and all I get is Array ( ) tried adding var_dump($errors), and I get array(0) { } Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371955 Share on other sites More sharing options...
Pikachu2000 Posted August 23, 2012 Share Posted August 23, 2012 Where did you add those? In the else{ echo 'failed'; etc. ? Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371956 Share on other sites More sharing options...
quasiman Posted August 23, 2012 Author Share Posted August 23, 2012 Yeah, sorry - should have been more clear...in the last else: } else { echo "failed<br>"; print_r($errors); var_dump($errors); echo $lostEmail . $subject . $txt . $headers . "<br>"; } Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371957 Share on other sites More sharing options...
quasiman Posted August 23, 2012 Author Share Posted August 23, 2012 What's funny to me is that I only have this problem when I use a valid email address in the DB. Fake or invalid addresses give me the correct messages. Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371961 Share on other sites More sharing options...
Pikachu2000 Posted August 23, 2012 Share Posted August 23, 2012 An empty array should evaluate to TRUE when you do if(!$array), but for grins let's try it the right way, and change that to if( empty($errors) ) instead and see if that makes any difference. Where is the code that initializes $errors as an empty array? Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371963 Share on other sites More sharing options...
xyph Posted August 23, 2012 Share Posted August 23, 2012 He's not checking against $errors, he's checking against errors You should start programming with error reporting turned on. It'll help you find your typos. Get ready for a potential huge wave of notices though Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371972 Share on other sites More sharing options...
quasiman Posted August 24, 2012 Author Share Posted August 24, 2012 I have at the top of the file: // Reset errors and success messages $errors = array(); $success = array(); ok......I changed my if statement to if( empty($errors) )and I'm returning $success['passwordSent']. I have two very similar pieces above this, for creating the user and for logging in....so I'm not sure why this issue is even happening. Anyway, now I can move onto the next problem. Thanks! Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371973 Share on other sites More sharing options...
Pikachu2000 Posted August 24, 2012 Share Posted August 24, 2012 LOL, wut? How the hell did I miss that?!? Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1371986 Share on other sites More sharing options...
quasiman Posted August 24, 2012 Author Share Posted August 24, 2012 Oh lord....No wonder it started working! LOL! Link to comment https://forums.phpfreaks.com/topic/267502-lost-password-formprobably-simple-trying-to-figure-out-what-im-doing-wrong/#findComment-1372035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.