0

les a user come on index.php page. he sees login form. but he forgot his password. so he click forgot password.
on forgotpassword.php page he fills a form.

<form action = 'forgotpassword.php' method = 'post'>
    Username: <input type='username' name='username'><br/>
    E-Mail: <input type='email' name = 'email'><br/>
    <input type='submit'  value='get password'>
    <a href="index.php">[BACK]</a>
</form>

when he is done, he hits submit button. keep in mind he is not login at this movment.
so php code runs. and i want to check that if user name he enter in form is in database.
to get the form user name i did

$username =  $_POST['username'];

now to check if $username is in database. code below works fine if user in logedin.
but problem is user is NOT loged in at this point. so $user = $_SESSION['username']; wont work

//usernamedb = get from table
$user = $_SESSION['username'];
$queryget = mysql_query("SELECT username FROM user WHERE username = '$user'") or die("query didnt work");
$row = mysql_fetch_assoc($queryget);    
$username_db = $row['username'];
3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by vibhaJ
1

ops its a typo. it should be text. thanks for leting me know.

does it solved your problem ?

    //usernamedb = get from table
    $user = $_SESSION['username'];
    $queryget = mysql_query("SELECT username FROM user WHERE username = '$user'") or die("query didnt work");
    $row = mysql_fetch_assoc($queryget);
    $username_db = $row['username'];

what form is this placed on ?

0

You can not use session during forget password.
Also you can only use email for checking:

<?
$email = $_POST['email'];
$queryget = mysql_query("SELECT username FROM user WHERE email = '$email'") or die("query didnt work");
$num_rows = mysql_num_rows($queryget);
if($num_rows > 0)
{
    $row = mysql_fetch_assoc($queryget);    
    $username = $row['username'];
    // Send email to {$email } whose username is  {$username}
}
else
{
    // such email doesn't exist
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.