我的脚本收到以下错误。
[Tue Dec 01 09:17:10 2015] [error] [client xxxx] PHP Notice: Undefined index: search in xxx/search.php on line 3, referer: http://xx/
此外,我有时也会收到以下错误
PHP Notice: Undefined offset: 4 in xxx/search.php on line 21, referer: http://xxx/search.php?search=C8053A-B&submit=Search
search.php的代码是
<?php
// Words
$words = trim($_GET["search"], ' ');
echo '<br>';
echo '<div align="center">';
echo '<form method="get" action="search.php?" id="searchform">';
echo '<input type="text" name="search">';
echo '<input type="submit" name="submit" value="Search">';
echo '</form>';
echo '</div>';
if ($words != '')
{
echo 'Search Results for <b>'.$words.'</b>:';
$file = fopen('inv.csv', 'r');
$crossw = $words;
$words = array($words);
$words = array_map('preg_quote', $words);
$regex = '/'.implode('|', $words).'/i';
print('<table border="1"><tr><td width="150">Primary Part #</td><td width="75">Price</td><td width="75">Qty Avail</td><td width="105">Searched #</td><td width="375">Description</td></tr></table>');
while (($line = fgetcsv($file)) !== FALSE) {
list($part, $price, $qty, $cross, $desc) = $line;
if(preg_match($regex, $cross)) {
print('<table border="1"><tr><td width="150">'.$part.'</td><td width="75">'.$price.'</td><td width="75">'.$qty.'</td><td width="105">'.$crossw.'</td><td width="375">'.$desc.'</td></tr></table>');
}
}
if ($crossw != '')
{
echo 'End of results.';
}}
?>
我希望在不关闭php.ini登录的情况下摆脱错误。
错误的来源/原因是什么?
答案 0 :(得分:1)
此通知邀请您考虑var result = $scope.url.includes('google.it') || $scope.url.includes('wikipedia.it');
url参数未设置的可能性(可能是您第一次浏览该搜索页时?)。
search
您在此假设$words = trim($_GET["search"], ' ');
变量始终可供您使用,但实际情况并非如此。
这种情况应该在php中正确处理,并带有̀$_GET["search"]
构造,并带有三元运算符(if / else语句的简写),如下所示:
isset()