xpath search php

i keep getting the following error messages

Notice: Undefined index: txtSearch in     /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11023553/public_html/holiday/searchprocess.php on line 11

Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Invalid expression in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11023553/public_html/holiday/searchprocess.php on line 22

Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: xmlXPathEval: evaluation failed in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11023553/public_html/holiday/searchprocess.php on line 22

Warning: Invalid argument supplied for foreach() in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11023553/public_html/holiday/searchprocess.php on line 26

then i try to run my search file


$header = makeHeader();

// create an instance
$holidayDoc =         simplexml_load_file('http://numyspace.co.uk/~unn_w11023553/holiday/holidays.xml');      

// set $studytype to either the upper case request or null
$txtSearch = $_GET["txtSearch"];

// set the query using the studytype
if (!is_null($txtSearch)) {
    $qry = "//channel/item[description[contains(text(),\"$txtSearch\")]]";
else {
// blank search entered so all holidays are shown.
    $qry = "/channel/'ALL'";

$holidays = $holidayDoc->xpath($qry);   // do the xpath query LINE 17
// now loop through all the students
echo "<table border=\"1\">\n";
echo "<tr><td>Title</td></tr>\n";
foreach ($holidays as $holiday) //LINE 21
echo <p><strong><a href = '$link'>'$holiday'</a></strong></p>


$footer = makeFooter();


been fiddling with it for about 2hrs and still can't work out where i've gone wrong, any insight would be greatly appreciated, thanks.



$txtSearch = $_GET["txtSearch"];


if( isset( $_GET["txtSearch"] ) && ( trim( $_GET["txtSearch"] ) != '' ) ) {
    $txtSearch = $_GET["txtSearch"];
} else {
    $txtSearch = null;

Hope this helps.

The first warning tells you that txtSearch is not a value in the $_GETarray of query string parameters. E.g. you have no ?txtSearch=something in the url you are invoking the script with.

So you need to check how you are invoking the script. Is the querystring parameter set? Did you spell it correctly?

You could debug a bit looking at the contents of $_GET by doing var_dump($_GET).

Need Your Help

DTOs vs Serializing Persisted Entities

c# web-services dto object-persistence

I'm curious to know what the community feels on this subject. I've recently come into the question with a NHibernate/WCF scenario(entities persisted at the service layer) and realized I may be goin...