Im tryin to construct an SQL statement, the criteria comes from six search boxes.
//construct the SQl statement for search facility
$bolFirst = "true";
$strSQL = "SELECT beneficiary_id, beneficiary_name FROM tblBeneficiaries";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
while(list($key,$val) = each ($_POST)) {
if ($val != "") {
if ($bolFirst != true) {
$strSQL = $strSQL . " OR ";
}
else {
$strSQL = $strSQL . " WHERE ";
}
if ($key = "beneficiary_id") {
$strSQL = $strSQL . $key . " = " . $val;
}
else {
$strSQL = $strSQL . "(" . $key . ") LIKE '%" . $val . "%'";
}
$bolFirst = false;
}
} while(list($key,$val) = each ($_POST));
}
$strSQL = $strSQL . " ORDER BY beneficiary_id ASC";
echo $strSQL;
This is the SQL i get if i fill all the form fields;
SELECT beneficiary_id, beneficiary_name FROM tblBeneficiaries WHERE beneficiary_id = 1 OR beneficiary_id = test OR beneficiary_id = fjlkj OR beneficiary_id = fjkjfk OR beneficiary_id = jsdkj ORDER BY beneficiary_id ASC
It doesnt seem to recognise any of the other fields, just sticks on beneficiary_id. Any help would be greatly appreciated.
Thanks