I am trying to setup a MySQL database search based on two choices either page id or by the page name.... It's supposed to populate the search string if the corresponding box is set, but it's not working.
Regardless of whether or not the boxes are populated, it puts the corresponding options into the string. Here is an example of if you hit the search button when both boxes are blank...
"SELECT * FROM pages WHERE searchid = and pagename = "
It should read like this:
"SELECT * FROM pages WHERE"
Actually it should just drop by to the search page, but one step at a time.
Here is the code:
if ($_SERVER['REQUEST_METHOD'] != "POST")
{
include 'search.html.php';
}
else
{
$searcharray = array();
$a = 0;
$searchid = NULL;
$pagename = NULL;
$searcharray[$a] = ('SELECT * FROM pages WHERE');
$a++;
$searchid = $_REQUEST['searchid'];
$pagename = $_REQUEST['pagename'];
if (isset($_REQUEST['searchid']))
{
$searcharray[$a] = ('searchid = ' . $searchid);
}
if (isset($_REQUEST['searchid'], $_REQUEST['pagename']))
{
$a++;
$searcharray[$a] = ('and ');
$a++;
}
if (isset($pagename))
{
$searcharray[$a] = ('pagename = ' . $_REQUEST['pagename']);
}
$sql = join('', $searcharray);
include 'searchres.html.php';
}
Just as a heads up, currently searchres.html.php is an echo statement to output the $sql string currently.
ANy help on why this is occuring would be great.... Thanks all.