I have done this many times before, to re-use a value passed into the sprintf() function. But this code is returning a “Warning: sprintf() [function.sprintf]: Too few arguments in…” message.
Here is the code:
$search_clause = sprintf(" (msgBody LIKE %%%1$s%% OR msgSubject LIKE '%%%1$s%%' ) ", mysql_real_escape_string($match1));
Ideally the value of $match1 will be inserted into the segment of the SQL WHERE clause shown above – twice, each wrapped by ‘%’ characters for a wildcard search.
If $match1 = “test”, the resulting string value of $search_clause would be:
(msgBody LIKE '%test' OR msgSubject LIKE '%test%' )
What is the obvious mistake I’m making??
The
$sis probably getting interpreted as a variable (see variable expansion). Try using single quotes instead: