enemeth Posted April 11, 2007 Share Posted April 11, 2007 hi there, i have a site that issues a password if you lose yours, but i cant get it to work , the code is below : <? include 'db.php'; switch($_POST['recover']){ default: include 'lostpsw.php'; break; case "recover": recover_pw($_POST['email_address']); break; } function recover_pw($email_address){ if(!$email_address){ echo "You forgot to enter your Email address"; include 'lostpsw.php'; exit(); } // quick check to see if record exists $sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'"); $sql_check_num = mysql_num_rows($sql_check); if($sql_check_num == 0){ echo "No records found matching your email address<br />"; include 'lostpsw.php'; exit(); } // Everything looks ok, generate password, update it and send it! function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); $sql = mysql_query("UPDATE users SET password='$db_password' WHERE email_address='$email_address'"); $subject = "Your Password at The Truth Discovered!"; $message = "Hi, we have reset your password. New Password: $random_password http://www.thetruthdiscovered.com/login.php Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: The Truth Discovered Webmaster< admin@mydomain.com>\n X-Mailer: PHP/" . phpversion()); echo "Your password has been sent! Please check your email!<br />"; include 'login.php'; } ?> and the form is : <?php include 'header.php'; ?> <center> <p align="center"><font face="Calligraphic" size="5" font color="white">New Password Request</font></p> <form action="lost_pw.php" method="post"> <font face="Calligraphic" font color='white' size="4"> Email Address:<font color='white'>*</font> <input type=text name='email_address' size=30><br><br><br> <input type="submit" value="Get Password" name="submit"> </form> </center> <br><br> <?php include 'footer.php'; ?> when i enter an email address and hit the get password button , it flashes and stays on the page that i am entering the email at , any ideas? Elaine Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted April 11, 2007 Share Posted April 11, 2007 Hmm, not sure. PS: The default case will always be chosen, I.E. in your select it will never get to the process option. switch($_POST['recover']){ default: include 'lostpsw.php'; break; case "recover": recover_pw($_POST['email_address']); break; } Should be: switch($_POST['recover']){ case "recover": { recover_pw($_POST['email_address']); break; } default: { include 'lostpsw.php'; break; } } Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 11, 2007 Author Share Posted April 11, 2007 hmm, i didnt work , does the same thing, just flashes, doesnt go further, Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 11, 2007 Share Posted April 11, 2007 WHAT!! The Switch statment was correct, Hmm, not sure. PS: The default case will always be chosen, I.E. in your select it will never get to the process option. switch($_POST['recover']){ default: include 'lostpsw.php'; break; case "recover": recover_pw($_POST['email_address']); break; } Should be: switch($_POST['recover']){ case "recover": { recover_pw($_POST['email_address']); break; } default: { include 'lostpsw.php'; break; } } Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 11, 2007 Share Posted April 11, 2007 Anyways what part fails ? the update or the email ? EDIT also do header.php & footer.php have <form action blar blaR> and </form> Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 11, 2007 Author Share Posted April 11, 2007 both fails, all it does is when you hit GET PASSWORD, it flashes and the email address you enter disappears, no errors, no emails nothing, maybe something is wrong in my form? Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 11, 2007 Share Posted April 11, 2007 you are missing the form tags whats in header.php ? try adding <form action="nameOFscript.php" method="POST"> after header.php and </form> before footer.php Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 11, 2007 Author Share Posted April 11, 2007 header.php and footer.php are the top and bottoms of my webpage that never changes, it has the menus and pictures , go see www.thetruthdiscovered.com <?php include 'header.php'; ?> <center> <p align="center"><font face="Calligraphic" size="5" font color="white">New Password Request</font></p> <form action="lost_pw.php" method="post"> <font face="Calligraphic" font color='white' size="4"> Email Address:<font color='white'>*</font> <input type=text name='email_address' size=30><br><br><br> <input type="submit" value="Get Password" name="submit"> </form> </center> <br><br> <?php include 'footer.php'; ?> it is as you said above Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 11, 2007 Share Posted April 11, 2007 Working ? If so please click solved (bottom left) Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 11, 2007 Author Share Posted April 11, 2007 no it is not working, i was just saying that what you said above about the form tags must be after and before the header and footer, and i replied that they are like that , still flashes and does nothing Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 OK try this <?php include 'db.php'; switch($_POST['recover']){ default: include 'lostpsw.php'; break; case "recover": recover_pw($_POST['email_address']); break; } // Everything looks ok, generate password, update it and send it! function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } function recover_pw($email_address){ if(!$email_address){ echo "You forgot to enter your Email address"; include 'lostpsw.php'; exit(); } // quick check to see if record exists $sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'"); $sql_check_num = mysql_num_rows($sql_check); if($sql_check_num == 0){ echo "No records found matching your email address<br />"; include 'lostpsw.php'; exit(); } $random_password = makeRandomPassword(); $db_password = md5($random_password); $sql = mysql_query("UPDATE users SET password='$db_password' WHERE email_address='$email_address'"); $subject = "Your Password at The Truth Discovered!"; $message = "Hi, we have reset your password. New Password: $random_password http://www.thetruthdiscovered.com/login.php Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: The Truth Discovered Webmaster< admin@mydomain.com>\n X-Mailer: PHP/" . phpversion()); echo "Your password has been sent! Please check your email!<br />"; include 'login.php'; } ?> Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 still flashes and does nothing , can it be in the form i have for the users to put there email in and click get password ? Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 are the form and the script on the same page ? if not then thats the problem as the form is calling itself if they card can you post the whole page (in [ code] tags) Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 there are two files, one called lost_pw.php and the other is lostpsw.php lost_pw.php is the php code that sends the email , lostpsw.php is the actual form that users see Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 ok add this to the form <input type=hidden name='recover' value='recover' size=30> as its not being set anywhere Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 OMG it worked your wonderful ! but there is a little issue ! i never got the email Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 I assume you got the message saying it was sent.. try another script mailtest.php $email_address = "your@email.com"; $subject = "Test"; $message = "Please Work"; $from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP/" . phpversion()" $mailcheck = mail($email_address, $subject, $message, $from); if($mailcheck) { echo "Your password has been sent! Please check your email!<br />"; }else{ echo "email..failed<br />"; } try that first see what happens Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 oh my where would i put this ? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 create a file called testmail.php and copy and past the following into it <?php $email_address = "your@email.com"; $subject = "Test"; $message = "Please Work"; $from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP/" . phpversion()" $mailcheck = mail($email_address, $subject, $message, $from); if($mailcheck) { echo "Your password has been sent! Please check your email!<br />"; }else{ echo "email..failed<br />"; } ?> change your@email.com to your email save upload to server and run.. see if it work.. also check your junk mail folder Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 i get this Parse error: parse error, unexpected '\"' in /home/www/thetruthdiscovered.com/testmail.php on line 5 mindu i dont see the unexpected \" anywhere! Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 12, 2007 Share Posted April 12, 2007 i get this Parse error: parse error, unexpected '\"' in /home/www/thetruthdiscovered.com/testmail.php on line 5 mindu i dont see the unexpected \" anywhere! You need a semicolon after and a double quote is missing. $from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP/" . phpversion()" Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 oops sorry i should of checked thats first here try this (i tested it) <?php $email_address = "email@ghdagsdhj.com"; $subject = "Test"; $message = "Please Work"; $from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP" . phpversion(); $mailcheck = mail($email_address, $subject, $message, $from); if($mailcheck) { echo "Your password has been sent! Please check your email!<br />"; }else{ echo "email..failed<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 i gives me the confirmation that it went through but it never gets there , and you no the funny thing is , i just registered at my site with bogus information and another email address i have just to test if it is working on that page (register.php) and i got that email , but not the one you got me to test nor the one to reset the password, funny! frustrating but i guess there is nothing else to do but laugh ! i want to thank you for all your help so far it is wonderful but it doesnt make sense that the email goes through with the register.php , but not with the other ones can maybe my webhost limit me to one mail() function? doesnt make sense Elaine Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 confirmation should mean its was sent.. have you tried another email address ? checked the junk mail folder etc? Quote Link to comment Share on other sites More sharing options...
enemeth Posted April 12, 2007 Author Share Posted April 12, 2007 yup tried two email address, and the junk folder nothing will try another one Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.