Reputation: 3
I am using PHP and have session_start(); and $_SESSION['username'] at the top of the page. The user is logged in just fine.
The problem is, I am trying to pull and display data from just the user that is logged on. Below is my current query and it is pulling from the first user in the table, not $_SESSION['username'] user. How do I adjust SELECT to specify to pull from the current logged on user? Thanks.
$result = mysql_query("SELECT * FROM members")
or die(mysql_error());
$row = mysql_fetch_array( $result );
echo "<strong>bio:</strong> ".$row['bio'].'<br />';
Upvotes: 0
Views: 6836
Reputation: 47776
mysql_query('SELECT * FROM members WHERE username = "'
. mysql_real_escape_string($_SESSION['username']) . '"')
or trigger_error(mysql_error());
You should read up on SQL and while you're at it, learn about SQL injections.
Upvotes: 2
Reputation:
you need to supply a WHERE clause to your query specifying which data you wish to retrieve. Xeon06 is right, this is SQL 101.
Upvotes: 0
Reputation: 146460
You need to use the WHERE clause. It should be explained in the first chapter of any SQL manual:
SELECT foo, bar
FROM members
WHERE members_id=31416
Upvotes: 0