tags:

views:

49

answers:

2

i have a problem with my coding. when i put 'where' in my query, it does not show anything. but when i do not put 'where' it display all the records. all i want is that, it will display the records of the current user that logged in..

please help me with this.

what will be the code for these?

anyone? :(

it will be a big help. thanks..

This is my query..

$query="SELECT * FROM members where username = '$username'";
$result=mysql_query($query);
$num=mysql_numrows($result);  

whenever i put WHERE , it doesn't display anything.

A: 

You'd better learn how to use WHERE correctly. You will need it in the future.

Could you please show us the query that gives all records, the first few lines from that, and the query with WHERE that fails?

It should be something like SELECT * from users WHERE loginname="Smith"

Of course, you would need to use WHERE on a column from the table. So, when you create the table, you should have added a loginname column, and whenever you INSERT a row, you should set the loginname value. If you don't store the loginname, you can't filter on it later. It's not magically remembered.

MSalters
$query="SELECT * FROM members where username = '$username'"; $result=mysql_query($query); $num=mysql_numrows($result);
mayumi
what i'm tryin to say is, when the user is currently logged in, it will automatically display its records. then how will it automatically display? if i manually put that ' WHERE lastname= "Smith" '.. and what if Smith is not the currently user?
mayumi
Oh! You'd better make that clear in the question itself.
MSalters
i know its not magically remembered. that's why im saking u guys.. what is the correct code for that.. thanks. :)
mayumi
+1  A: 

Start by echoing out your $query just before the mysql_query statement, so you can check that it's what you expect. Then put some error handling in your code to identify if there's a database error being returned:

$query="SELECT * FROM members where username = '$username'";
echo $query.'<br />';
$result=mysql_query($query); 
if (!$result) {
    die('Error executing query: ' . mysql_errno().' '.mysql_error());
}
$num=mysql_numrows($result); 

These are absolute basics that you should always be doing before asking for help.

Also, try escaping $username before using it in your query

Mark Baker
ow, thank you mr. mark. ok . i will use it
mayumi