Jump to content

[SOLVED] select statement with multiple conditions


tommy445

Recommended Posts

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!

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']}'";

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

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'";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.