Question

I have an existing query that uses sprintf to incorporate a php and mysql into a custom MySQL query.

This works great:

$query_EmpVSP = sprintf("SELECT * FROM HTG_VSP WHERE HomeOfEmpNumber IS NULL OR HomeOfEmpNumber = '' OR HomeOfEmpNumber = %s", GetSQLValueString($colname_EmpVSP, "text"));

I need to add a second OR statement for another column called CustomForEmpNumber and want to re-use the $colname_EmpVSP value.

When I add

. "OR HomeOfEmpNumber = %s", GetSQLValueString($colname_EmpVSP, "text"));

I get a invalid syntax at %s

Here is the current query that shows the error:

$query_EmpVSP = sprintf("SELECT * FROM HTG_VSP WHERE HomeOfEmpNumber IS NULL OR HomeOfEmpNumber = '' OR HomeOfEmpNumber = %s", GetSQLValueString($colname_EmpVSP, "text") . " OR CustomForEmpNumber = %s", GetSQLValueString($colname_EmpVSP, "text"));
Was it helpful?

Solution

Try this:

$sql = "SELECT * FROM HTG_VSP WHERE HomeOfEmpNumber IS NULL OR HomeOfEmpNumber = '' OR HomeOfEmpNumber = %s or CustomForEmpNumber = %s"; 
$query_EmpVSP = sprintf($sql,GetSQLValueString($colname_EmpVSP, "text"),GetSQLValueString($colname_EmpVSP, "text"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top