0

I have a problem with this code:

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

I'm using this code to pass a value from this page to this page with $id and it is not empty I echoed $id and it holds the value. And this is the code on the receiving end:

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

currently having this error note and I expect the 2nd else statement should retrieve the code.

Notice: Undefined index: student_id in C:\xampp\htdocs\Thesis\search_enroll.php on line 37
1
  • Your string is messed up, count your quotes. Also, be sure to sanitize any variables before doing anything with them. i.e: addslashes, check if is number, etc. Commented Aug 29, 2012 at 12:38

5 Answers 5

2

Do your string escaping right or don't do it at all:

<?php
    echo "<meta http-equiv='refresh'
                content='3;search_enroll.php?id=".$id."' />"; ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Not a problem, but you should really look into that matter right away. If you learn it wrong, you'll never get the hang of it!
0

The meta is not used like that. You hate to specify the URL on a URL subattribute and not just on the CONTENT attribute like that

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

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

there, your param is never setted

Comments

0

Use the @ suppressor in front of a variable when Undefined index error occur.

This error occur when variable is not declared first and we used in code:

For eg.

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

But in your case there this else condition should not be run .

Comments

0

You should do:

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

This will make sure the student_id key exists in $_REQUEST before you try to access it.

Without a check, it will throw the Notice

Comments

0

This error appears because of your PHP error reporting settings.

Usually, it appears when your variable is not properly set.

Check if $_POST['action'] is set before using it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.