Bruke Posted July 7, 2008 Share Posted July 7, 2008 Hi, In a nutshell, I'm trying to write a SELECT query that has two WHERE values that are conjoined by the AND logical operator... here's what I've got so far: SELECT * FROM client WHERE client_status = {$_GET['client_status']} && user_id = {$_SESSION['MM_User']} ORDER BY client_lastname ASC My purpose is to allow a company's agent to review clients according to client status, limiting it to just clients that belong to that agent's accounts. The "user_id" value is a primary key for the user table, to which each agent is a row; it's also a foreign key in the client table as it identifies which agent is responsible for which client. The "client_status" is an enumerated value, either "lead" or "customer". I had a similar issue with a similar bit elsewhere in the application, but in that case I discovered that the problem was that a session variable was not correctly set. I've checked the page that directs to this, and it sets the client_status properly; likewise I've double-checked that the session variable is being set correctly here and it is. The error I'm getting is this: "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 'ORDER BY client_lastname ASC LIMIT 0, 10' at line 1" I'm not clear why it has that "LIMIT 0, 10' at line 1" part; I do have it set up to display only 10 records per page, but I don't think that's the problem. I'm using the most current versions of php and mysql (I'm not the one that manages that part of the server, but I asked and that's what I was told). What is wrong with my syntax? I thank you in advance for your time and help. Link to comment https://forums.phpfreaks.com/topic/113590-multiple-where-conjoined-by-and/ Share on other sites More sharing options...
discomatt Posted July 7, 2008 Share Posted July 7, 2008 You need quotes around strings in mysql SELECT * FROM client WHERE client_status = '{$_GET['client_status']}' && user_id = '{$_SESSION['MM_User']}' ORDER BY client_lastname ASC Don't forget to sanitize user input as well! Link to comment https://forums.phpfreaks.com/topic/113590-multiple-where-conjoined-by-and/#findComment-583633 Share on other sites More sharing options...
Bruke Posted July 7, 2008 Author Share Posted July 7, 2008 Yep, that works. I feel a bit sheepish for missing the obvious... Thanks! Link to comment https://forums.phpfreaks.com/topic/113590-multiple-where-conjoined-by-and/#findComment-583651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.