Question: My question supposed to be simple! although, I couldn't find the correct answer!

I need to retrieve the "hashed password" for the giving "username" from mySql database with php, then I need to store it in a variable, how could I do that?

All what I get is `"Resource id #5"`!

This is my code:

```
$query = "SELECT hashed_password ";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "AND hashed_password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
echo "$result_set"; 
echo '</br>';

```

Answer: 
To start off, let's use a MySQL library that supports prepared statements - otherwise, we'll run into SQL Injection issues in the future. Now, back to the actual question / answer.

If we use MySQLi, we have a few functions that will help us. Here's an example of an answer to your question w/ code comments to help walk through it:

```
// create our db connection
$mysqli = new mysqli('localhost', 'db_username', 'db_password', 'db_table');

// create a Prepared Statement to query to db
$stmt = $mysqli->prepare('SELECT hashed_password FROM users WHERE username = ? LIMIT 1');

// dynamically bind the supplied "username" value
$stmt->bind_param('s', $username);

// execute the query
$stmt->execute();

// get the first result and store the first column in the `$hashed_password` variable
$stmt->bind_result($hashed_password);
$stmt->fetch();

// close our Prepared Statement and the db connection
$stmt->close();
$mysqli->close();

echo $hashed_password;

```

Check out the PHP Doc for [`mysqli::prepare()`](http://php.net/manual/en/mysqli.prepare.php) for more examples =]

Note: I *highly* recommend avoiding the `mysql_query()` (and family) functions. They are not only deprecated, but they are quite insecure to use.
You need to fetch the data out of the mysql-resource that is returned by a query.

Just pass it through `mysql_fetch_assoc($result_set)`. It will return your data in a nice and ordered arraay, moving ahead one row every call.
Meaning you can do
`while ($row = mysql_fetch_assoc($result_set)`.

Also, please use mysqli. Its basically the same just with `mysqli` instead of `mysql` in commands. See the docs here for more info: <http://php.net/manual/en/book.mysqli.php>