I am using PHP and have session_start(); and $_SESSION['username'] a开发者_如何学Pythont 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 />';
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.
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
You should look into the SQL WHERE
clause.
you need to supply a WHERE clause to your query specifying which data you wish to retrieve. Xeon06 is right, this is SQL 101.
精彩评论