tommy445 Posted April 8, 2009 Share Posted April 8, 2009 I am trying to select table with multiple conditions. Point of focus is that the conditions are coming from a form input. This is what I have $sel = "select * from site_clients where client_first_name, client_last_name, client_account_number='".$_POST['client_first_name','client_last_name', 'client_account_number']."'"; The error I'm receiving is: Parse error: syntax error, unexpected ',', expecting ']' in Please Help! Quote Link to comment https://forums.phpfreaks.com/topic/153247-solved-select-statement-with-multiple-conditions/ Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 You need to check out some basic SQL syntax. Your arrays were missing ']', you didn't use AND for multiple where clause, and some other stuff I fixed. $sel = "SELECT * FROM site_clients WHERE client_first_name = '{$_POST['client_first_name']}' AND client_last_name = '{$_POST['client_last_name']}' AND client_account_number= '{$_POST['client_account_number']}'"; Quote Link to comment https://forums.phpfreaks.com/topic/153247-solved-select-statement-with-multiple-conditions/#findComment-805057 Share on other sites More sharing options...
tommy445 Posted April 9, 2009 Author Share Posted April 9, 2009 Thank you much. One more thing. what is the difference between your assisted code and the one below. They both work. $sel = "select * from site_clients where client_first_name ='".$_POST['client_first_name']."' and client_last_name ='".$_POST['client_last_name']."' and client_account_number ='".$_POST['client_account_number']."' " ; Specific code difference { vs. ". and } vs ." Thanks Quote Link to comment https://forums.phpfreaks.com/topic/153247-solved-select-statement-with-multiple-conditions/#findComment-805632 Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 When you use the double quotes you're breaking out of the string into PHP. The reason I used { } is because in the POST array there are single quotes that would have thrown an error. But, if you don't have single quotes, for example just a regular variable you don't have to use either of these and the variable will still interpolate. i.e. $first = $_POST['client_first_name']; $sel = "SELECT * FROM site_clients WHERE client_first_name = '$first'"; Quote Link to comment https://forums.phpfreaks.com/topic/153247-solved-select-statement-with-multiple-conditions/#findComment-805636 Share on other sites More sharing options...
tommy445 Posted April 9, 2009 Author Share Posted April 9, 2009 Thank you again for your help! Quote Link to comment https://forums.phpfreaks.com/topic/153247-solved-select-statement-with-multiple-conditions/#findComment-805803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.