I trying to create a MySql Query from the $_POST values trouble is i don’t want to use all the $_POST values as some are used for other things so i am trying to compare the value names against an array to see if they are actual filed in the DB then if they are create a Query string out of the names an values
this is what i have up to now
$i = 1;
$b = 1;
$cnt = count($_POST);
foreach ($_POST as $key => $entry)
{
$array = array('Country', 'County', 'Age', 'ect', 'ect');
foreach ($array as $arrayValue) {
if ($arrayValue == $key) {
$b++;
if($i == 1) {$query[] = "$key='$entry'";}
elseif($cnt == $b) {$query[] = "$key='$entry'";}
else {$query[] = "$key='$entry' AND ";}
$i++;
}
}
}
I have gotten stuck now im not sure how to turn all the values out of the $QUERY array into a single string ie $search = "country='United Kingdom' AND county ='example'"
Any help would be much appreciated.
1 Answer