Good, got email with password. Code working properly.
Good, got email with password. Code working properly.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
http://php.flashwebhost.com/sherly/lost_password.html
lost_password.php
Code:<?php if (isset($_POST['email'])) { $email = $_POST['email']; } else { die('Please enter your email address'); } $email = trim($email); $db_server = '127.0.0.1'; $db_user = 'fwhphp_user'; $db_password = 'k5BJRaX6SFbs'; $db_name = 'fwhphp_db'; $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name); if ($mysqli->connect_errno) { echo 'Connect failed: ' . $mysqli->connect_error; exit(); } $sql = "select * from users where email='$email'"; // Now time to execute the SQL statement. $result = $mysqli->query($sql); if ($result->num_rows == 0) { die("User with email address <b>$email</b> not found"); } $name = $userInfo['name']; $password = $userInfo['password']; mail($email,"Your password", "Hello $name, your password is $password"); echo 'The password has been sent to the e-mail address specified;
Password not received, just got an mail with " Hello , your password is."
http://php.flashwebhost.com/stefin/lost_password.html
http://php.flashwebhost.com/stefin/lost_password.php
PHP Code:
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'];
} else {
die('Please enter your email address');
}
$email = trim($email);
$db_server = '127.0.0.1';
$db_user = 'fwhphp_user';
$db_password = 'k5BJRaX6SFbs';
$db_name = 'fwhphp_db';
$mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
if ($mysqli->connect_errno) {
echo 'Connect failed: ' . $mysqli->connect_error;
exit();
}
$sql = "select * from users where email='$email'";
$result = $mysqli->query($sql);
if ($result->num_rows == 0) {
die("User with email address <b>$email</b> not found");
}
$name = $userInfo['name'];
$password = $userInfo['password'];
mail($email,"Your password", "Hello $name, your password is $password");
echo 'New Password send to your email';
Last edited by stefin; 07-31-2014 at 01:55 AM.
Stefin, your program is missing 1 line.
This need to be added after codePHP Code:$userInfo = mysqli_fetch_assoc($result);
What that line do is fetch (means read, get, etc..) user information from MySQL query result.PHP Code:if ($result->num_rows == 0) {
die("User with email address <b>$email</b> not found");
}
@annie made that mistake (but actual code worked, i verified), @sherly copied it @stefin reported the mistake :D
@sherly
http://php.flashwebhost.com/sherly/lost_password.html
This is wrong code. You put code for index.html in lost_password.html
Please reupload the code, try to understand, if you don't understand ask here, that help everyone.
Now stefin asked the question, and we found a problem with posted codes.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
Code Fixed, Mail received with password.
PHP Code:
<?php
if (isset($_POST['email'])) { $email = $_POST['email'];} else { die('Please enter your email address');}
$email = trim($email);
$db_server = '127.0.0.1';$db_user = 'fwhphp_user';$db_password = 'k5BJRaX6SFbs';$db_name = 'fwhphp_db';
$mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
if ($mysqli->connect_errno) { echo 'Connect failed: ' . $mysqli->connect_error; exit();}
$sql = "select * from users where email='$email'";
$result = $mysqli->query($sql);
if ($result->num_rows == 0) { die("User with email address <b>$email</b> not found");}
$userInfo = mysqli_fetch_assoc($result);
$name = $userInfo['name'];$password = $userInfo['password'];mail($email,"Your password", "Hello $name, your password is $password");
echo 'New Password send to your email';
I got email with password
http://php.flashwebhost.com/sherly/lost_password.html
http://php.flashwebhost.com/sherly/lost_password.php
Code:<?php if (isset($_POST['email'])) { $email = $_POST['email']; } else { die('Please enter your email address'); } $email = trim($email); $db_server = '127.0.0.1'; $db_user = 'fwhphp_user'; $db_password = 'k5BJRaX6SFbs'; $db_name = 'fwhphp_db'; $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name); if ($mysqli->connect_errno) { echo 'Connect failed: ' . $mysqli->connect_error; exit(); } $sql = "select * from users where email='$email'"; $result = $mysqli->query($sql); if ($result->num_rows == 0) { die("User with email address <b>$email</b> not found"); } $userInfo = mysqli_fetch_assoc($result); $name = $userInfo['name']; $password = $userInfo['password']; mail($email,"Your password", "Hello $name, your password is $password"); echo 'The password has been sent to the e-mail address specified';
@stefin, good, the code lost formatting, but it is ok, may be problem with editor.
@sherly, nice, now it works.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
Bookmarks