php - MySQL query - where search with empty variable -


this elementary thing, can't find answer anywhere. need use equals variable post.

but don't know if variable empty or not. have lot of parameters use in query, not every entered. have use if/else, or can search through database empty variable?

if parameter variable not empty, want find rows in databse. if empty, want rows.

you can use this:

$db->query("select field table filter = '" . (isset($_post['field']) ? $db->real_escape_string($_post['field']) : "") . "'"); 

this prevents notices, if post variable not set. can use this, if variable set (just normal):

$db->query("select field table filter = '" . $db->real_escape_string($_post['field']) . "'"); 

also, can use prepared statements etc.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -