hi im trying to search an XML document using a combo box so the user can search in either description or title. I have loaded the XML file to the page that i wish to display the searches on. The search box its self is attached to a top.php document. I have tried to store the variable and apply them to a XML search string. i get the following errors but am unsure how to proceed.
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Invalid expression in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/web/searchResults.php on line 19
Warning: Invalid argument supplied for foreach() in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/web/searchResults.php on line 22
searchResults.php
<?php
include "top.php";
$holidaysXML = simplexml_load_file('holidays.xml');
if(isset($_POST["txtSearch"]) && $_POST["txtSearch"] != "Holiday Search..." && $_POST["txtSearch"] !="")
{
$txtSearch = $_POST["txtSearch"];
$searchOption = $_POST["searchOption"];
if($_POST["searchOption"] != "null")
{
$searchOption = $_POST["searchOption"];
$searchedResult = "Search results for \"$txtSearch\" in $searchOption";
$resultsHoliday = "channel/item [contains($searchOption, \"$txtSearch\")]";
}
}
$allHolidays = $holidaysXML->xpath($resultsHoliday);
foreach ($allHolidays as $currentHoliday)
{
echo "<a href= \"{$currentHoliday->link}\" style=\"font-weight:normal\" target=\"_blank\">{$currentHoliday->title}</a><br>";
echo "{$currentHoliday->pubDate}<br>";
echo "{$currentHoliday->description}";
}
This is where the information is gathered from the user on top.php
<form action = "searchResults.php" method = "post">
<input type = "text" name = "txtSearch" value = "Holiday Search...">
<select name = "searchOption">
<option value = "null" selected>(select)</option>
<option value = "title">Title</option>
<option value = "description">Description</option>
</select>
<input type = "submit" name = "search" value = "Search">
</form>