0

Here is my PHP Query, but it doesn't seem to order the results. Everything else works fine.

SELECT *  
FROM   `main` 
WHERE  `user_legacy` LIKE '%".$name."%' 
ORDER BY 'user_legacy' DESC LIMIT ".$limit
1
  • try removing the quotes in ORDER BY 'user_legacy' Commented Feb 19, 2012 at 8:44

3 Answers 3

3

You use backticks (') to quote column names in SQL, not the normal single quote (').

ORDER BY `user_legacy` DESC

Also, if you don't do any kind of vetting or your input, that query is potentially vulnerable to an SQL injection.

Sign up to request clarification or add additional context in comments.

1 Comment

I do strip the inputs, so there is no sql injection possibility. thanks for the detailed answer.
3

Don't quote the column name.

ORDER BY user_legacy

Comments

3

ORDER BY needs a column name, you're passing it a string. Lose the quotes.

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.