Hi everyone,
I hope you PHP gurus can help me out on this because I am stuck and can't seem to figure out where to go. I am learning PHP and perhaps biting off more than I can chew.
I have a form that has several fields that the user can enter data in to search the database. Non of these fields are required. They can leave some blank or fill them all in if they wish. Additionally, there are a couple of areas that have a range. Such as I want to search from X to Y.
The form is set up, no problems there. Now the coding for how PHP works to query the results is my issue. I first needed to remove any of the blank fields because I was having an issue where if a field was blank it was searching for empty records and returning nothing.
Here is my code to remove the blank fields:
foreach ($_POST as $field => $value)
{
$_POST[$field]=trim($value);
if ($field != "search")
{
if ($value !== "")
{
$cleaned_array[$field] = $value;
}
}
}
This works fine and returns only the fields that are entered. The problem is now I have no clue how to actually get the cleaned data into a mysql_query so that it can be used in a search.
Thanks for any help you can give me.