I have a SQL db of recipes. The tables are set up like this:
recipes
food_category
which_meal
I want users to be able to search 2 ways: by checking boxes and also by text string.
The following is the php code for the 1st way (checkboxes):
<?php
error_reporting(E_ALL);
if (isset($search)) // perform search only if a string was entered.
{
mysql_connect("", "_user", "_pword") or die("Could not connect: " . mysql_error());
echo "Connected successfully"; mysql_select_db("recipes") or die("Could not select database");
mysql_query("SELECT recipes.name,recipes.description FROM recipes INNER JOIN food_category,which_meal ON recipes.recipe_id = food_category.recipe_id . WHERE which_meal LIKE '$search' || food_category LIKE '$search' || dish_type LIKE '$search' LIMIT 0, 30'");
$result = mysql_query($search)or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{ //begin 'test' while
print_r($row);
} // end 'test' while
}
else { echo "problems..."; }
?>
I would like the results to display on the 'Search Results' page, but I have not been able to 1) get any results and 2) I keep getting "problems" displaying on the Search page before the checkbox section on the page...
http://www.thepastaboard.com/recipes/recipe_search_main.php3
If I check one of the boxes and submit the query the error I get on the 'Search Results' page is this:
NOTICE: Undefined variable: search
This is the php code I have on the 'Search Results' page:
<?php
error_reporting(E_ALL);
if (isset($search)) // perform search only if a string was entered.
{
mysql_connect("", "_user", "_pword") or die ("Problem connecting to Database");
$result = mysql_query("recipes", $search);
while($row=mysql_fetch_assoc($result))
{ //begin 'test' while
print_r($row);
} // end 'test' while
} else { echo "problems...."; }
?>
Does anyone have any idea what is going on? Please understand that I am a newbie and am trying very hard to learn php/sql!!!
Thanks in advance~