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'];

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

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 ?

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
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.