0

This line: $quey1="select * from clients WHERE USER == $current_user->user_login;";

It returns an unknown error. There must be a simple syntax error in my code but I cannot seem to figure it out. BTW $current_user->user_login; returns a user, like admin for example.

Any idea what is wrong here? I'm realy new to this (first time ever touching php and mysql)

thank you for your help!

4 Answers 4

4
$quey1 = "SELECT * FROM clients WHERE USER = '" . $current_user->user_login . "'"

You should look after these also:

  • escaping
  • prepared statements
  • PDO
Sign up to request clarification or add additional context in comments.

2 Comments

thanks :). this works great! Could you explain what the "." are for? what do they mean?
They mean string concratenation but the main problem was the missing single qoutes and the wrong operator (==).
2

PHP variables can be used in SQL queries (provided double quotes are used as single quotes are treated as string literals (so $something is literally interpreted as $something, not a variable), their values are simply substituted at the time of the query, however variable manipulatin is not possible. Your best bet is to replace it with a single variable. Also the semicolon in the query is not needed, as it is interpreted as a column. The == can be replaced with just = as you are extracting data, not setting data:

$user = $current_user->user_login;
$quey1 = "select * from clients WHERE USER == $user";

Comments

1

You don't need a double equals operator in MySQL. And any string comparison needs quotes.

$quey1 = "select * from clients WHERE USER = '{$current_user->user_login}'";

Comments

0

You need to wrap current_user->user_login in quotes. Otherwise MySQL thinks that it's a column. The error is that there is no column called "admin."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.