Php传递值

时间:2012-08-29 12:34:50

标签: php

我对此代码有疑问:

    <?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

5 个答案:

答案 0 :(得分:2)

你的字符串是否正确转义或根本不执行:

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

答案 1 :(得分:0)

由于您的PHP错误报告设置而出现此错误。

通常,在未正确设置变量时会出现。

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

答案 2 :(得分:0)

meta不是那样使用的。您不想在URL子属性上指定URL,而不是像

那样在CONTENT属性上指定URL
<META HTTP-EQUIV="Refresh" CONTENT="n; URL=MyURL">

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

那里,你的参数从未被设置

答案 3 :(得分:0)

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

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

例如。

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

但在你的情况下,不应该运行其他条件。

答案 4 :(得分:0)

你应该这样做:

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

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

如果没有检查,它将抛出{{1}}