0

我不断收到以下错误消息

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
Title

然后我尝试运行我的搜索文件

<?php
include('functions.php');

$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 
echo <p><strong><a href = '$link'>'$holiday'</a></strong></p>
    <p><small>$published</small></p>";

}


$footer = makeFooter();

?>

摆弄了大约 2 小时,但仍然无法找出我出错的地方,任何见解将不胜感激,谢谢。

4

2 回答 2

0

第一个警告告诉您这txtSearch不是$_GET查询字符串参数数组中的值。例如,您?txtSearch=something在调用脚本的 url 中没有。

所以你需要检查你是如何调用脚本的。是否设置了查询字符串参数?拼写是否正确呢?

$_GET您可以通过做来调试一下查看的内容var_dump($_GET)

于 2012-04-13T12:32:46.223 回答
0

代替

$txtSearch = $_GET["txtSearch"];

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

希望这可以帮助。

于 2012-04-13T13:31:09.643 回答