This question already has answers here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
(28个答案)
6年前关闭。
出现未定义索引错误,不确定是什么错误?这可能是错误所在。
if($ topic ['name'] == $ _GET ['topic'] || $ post ['topic_id'] == $ topic ['id']){**
(28个答案)
6年前关闭。
<?php
$qr_topic = @mysql_query("SELECT * FROM topics");
while ($topic = @mysql_fetch_array($qr_topic)) {
$highlight = "";
**if ($topic['name'] == $_GET['topic'] || $post['topic_id'] == $topic['id']) {**
$highlight = "class='highlight'";
}
echo "<li ".$highlight."><a href='index.php?topic=".$topic['name']."'>".$topic['name']."<img src='img/".$topic['image']."' width='195' height='90' /></a></li>";
}
?>
出现未定义索引错误,不确定是什么错误?这可能是错误所在。
if($ topic ['name'] == $ _GET ['topic'] || $ post ['topic_id'] == $ topic ['id']){**
最佳答案
您尝试使用$ _GET ['topic']而不先检查它是否首先存在,这就是为什么会出现该错误的原因。我建议您先使用is_set()或empty()测试变量是否存在。
08-28 17:34