Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.