proctk Posted July 23, 2006 Share Posted July 23, 2006 HiI have been working through the above tutorial. I have been able to get everything to work except the password recovery utility. I created the form see belowany thought why this is not working<body><form id="form1" name="form1" method="post" action="codeLostPassword.php"> <label for="textfield">Email Address:</label> <input type="text" name="email_address" id="email_address" /> <input name="hiddenField" type="hidden" value="recover" /> <input type="submit" name="Submit" value="Submit" id="Submit" /></form></body>and made a few changes to the code for regenerating the password. (file names only)[code=php:0]<?php session_start(); ?><?include 'db.php';switch($_POST['recover']){ default: include 'lost_pw.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 <strong>Knucklehead</strong><br />"; include 'lost_pw.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 'lost_pw.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 MyWebsite!"; $message = "Hi, we have reset your password. New Password: $random_password http://www.mywebsite.com/login.php Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\n X-Mailer: PHP/" . phpversion()); echo "Your password has been sent! Please check your email!<br />"; include 'login.php';}?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/15410-tutorial-creating-a-membership-system-with-php-and-mysql/ Share on other sites More sharing options...
Orio Posted July 23, 2006 Share Posted July 23, 2006 The problem is here:[code=php:0]switch($_POST['recover']){ default: include 'lost_pw.php'; break; case "recover": recover_pw($_POST['email_address']); break;[/code]$_POST['recover'] Should be $_POST['hiddenField']Also, change- "if(!$email_address){" to "if(empty($email_address)){"Orio. Quote Link to comment https://forums.phpfreaks.com/topic/15410-tutorial-creating-a-membership-system-with-php-and-mysql/#findComment-62461 Share on other sites More sharing options...
proctk Posted July 23, 2006 Author Share Posted July 23, 2006 Thank you very much, that solved my problem Quote Link to comment https://forums.phpfreaks.com/topic/15410-tutorial-creating-a-membership-system-with-php-and-mysql/#findComment-62463 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.