未定义的索引:C中的主题:第9行包含\ topic_list.php

时间:2014-06-07 18:42:25

标签: php mysql error-handling syntax-error undefined

            <?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']){**

1 个答案:

答案 0 :(得分:0)

您尝试使用$ _GET ['topic']而不检查它是否存在,这就是您收到该错误的原因。我建议你先使用is_set()或empty()来测试变量是否存在。

相关问题