Mysql query help

Suspended
Joined
30 Aug 2004
Posts
9,206
$query = "SELECT * FROM user WHERE user_name = &authenticatedUser left join account on user_id = fk1_user_id WHERE fk1_user_type_id = '1'


The following code should be to allow a user to login and then look at their customer details and only their details. I can get it so it selects * from the user table which is linked to another table with account information in but how do I get it so it only shows the customer that is logged in?


thanks
 
You've got two separate where statements, that should be giving you an error rather than the wrong results though. I would have thought the proper syntax would be:

Code:
$query = "SELECT * FROM user left join account 
on user_id = fk1_user_id 
WHERE user_name = &authenticatedUser
and fk1_user_type_id = '1'
 
thanks. Its says this now. Am i just missing something really small?

Error in query: SELECT * FROM user left join account on user_id = fk1_user_id WHERE user_name = &authenticatedUser and fk1_user_type_id = '1'. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '&authenticatedUser and fk1_user_type_id = '1'' at line 1

this is the code ive got

$query = "SELECT * FROM user left join account on user_id = fk1_user_id WHERE user_name = &authenticatedUser and fk1_user_type_id = '1'";
 
Single quotes around string variables :)

Edit: Haha well spotted :D - Dollar signs must precede variable names in PHP - ampersand means nowt :)
 
thanks works like this -


$query = "SELECT * FROM user left join account on user_id = fk1_user_id WHERE user_name = '$authenticatedUser' and fk1_user_type_id = '1'";
 
Back
Top Bottom