Echo the contents of $sql to see for sure what you have. Then run that query from the command line or phpmyadmin to see what it does.
My guess is that one of your variables isn't set right. You have a lot of similar looking variables that might've gotten mixed up (user, username, Cname, Client, client, clientId, ClientId, ClientRef, etc)