0

我对这段代码有疑问:

    <?php   echo "<meta http-equiv='refresh' content='3;search_enroll.php?&id='.$id />"; ?>

我正在使用此代码将此页面中的值传递到此页面,$id并且它不是空的,我回显了$id它并保存了该值。这是接收端的代码:

   <?php
            if (isset($_POST['SearchS'])){
                $id = $_POST['searchstudent'];

            }else if(!empty($_GET['id'])){
                $id = $_GET['id'];
            }
            else if(!empty($_GET['student_id'])){
                $id = $_GET['student_id'];
            }

            else {
                $id= $_REQUEST['student_id']; <--- this is line 37
            }
            ?>

目前有这个错误说明,我希望第二条else语句应该检索代码。

Notice: Undefined index: student_id in C:\xampp\htdocs\Thesis\search_enroll.php on line 37
4

5 回答 5

2

是否正确转义字符串或根本不这样做:

<?php
    echo "<meta http-equiv='refresh'
                content='3;search_enroll.php?id=".$id."' />"; ?>
于 2012-08-29T12:36:18.970 回答
0

出现此错误是因为您的 PHP 错误报告设置。

通常,它会在您的变量设置不正确时出现。

使用前检查是否$_POST['action']已设置。

于 2012-08-29T12:38:41.567 回答
0

你应该做:

else {
    if(isset($_REQUEST['student_id'])){
        $id= $_REQUEST['student_id'];
    }
}

这将确保在您尝试访问之前student_id存在密钥。$_REQUEST

没有检查,它会抛出Notice

于 2012-08-29T14:32:29.000 回答
0

元数据不是那样使用的。您讨厌在 URL 子属性上指定 URL,而不仅仅是在这样的 CONTENT 属性上

<META HTTP-EQUIV="Refresh" CONTENT="n; URL=MyURL">

http://en.wikipedia.org/wiki/Meta_refresh

在那里,你的参数永远不会设置

于 2012-08-29T12:40:39.410 回答
0

发生错误时,在变量前使用@抑制器 。Undefined index

当变量没有首先声明并且我们在代码中使用时会发生此错误:

例如。

 else {
     @$id= @$_REQUEST['student_id']; <--- this is line 37
 }

但是在您的情况下,不应运行此 else 条件。

于 2012-08-29T12:42:56.463 回答