2

I am trying to pass a variable between two webpages via a url and using php. I am getting the undefined index error.

I have tried multiple ways of doing this and spent the last several hours googling the problem and think the following code should work -- probably just a conceptual error. Am not using ISSET at this point because this is a url pass and it should be set.

The following code is on the passing page:

<DIV>
   <ul>                                    
     <li> <a href ="bulletindisplay.php?link = Bulletins/December_24_2014.pdf" title="Christmas Eve 2014">Christmas Eve, 2014 </a>; </li>     
   </ul>  
  </DIV>

The following code is on bulletindisplay.php

   <div>        
    <?php   
       $link =  $_GET['link'];
       echo $link;
      ?> 
    </div>   

Does anyone see my error? Thank you so much for any help.

Kkarinisme
  • 21
  • 3

5 Answers5

1

Remove all spaces inside href attribute:

  <DIV>
   <ul>                                    
     <li> <a href="bulletindisplay.php?link=Bulletins/December_24_2014.pdf" title="Christmas Eve 2014">Christmas Eve, 2014 </a>; </li>     
   </ul>  
  </DIV>
Ragnar
  • 4,393
  • 1
  • 27
  • 40
1

You need to remove the space after link in your URL. And you should be using isset because if link is not present in the query string you will see a PHP error.

1. if(isset($_GET['link'])) {
2.     $link = $_GET['link'];
3.     echo $link;
4. }
Ryan
  • 14,392
  • 8
  • 62
  • 102
1

Just remove spaces inside your link.

bulletindisplay.php?link=Bulletins/December_24_2014.pdf

Branimir Đurek
  • 632
  • 5
  • 13
1

Remove all spaces and use below code:

<li> <a href="bulletindisplay.php?link=Bulletins/December_24_2014.pdf" title="Christmas Eve 2014">Christmas Eve, 2014 </a>; </li> 

and in php :

if(isset($_GET['link'])) {
 $link = $_GET['link'];
 echo $link;
 }
Priyank
  • 3,778
  • 3
  • 29
  • 48
1

link = Bulletins/December_24_2014.pdf
//there is a space after link
If you print out $_GET you will get output like this

Array ( [link_] => Bulletins/December_24_2014.pdf )

So

$_GET['link'] !=$_GET['link_']
//$_GET['link'] is not set that's why you got the error
oldlearner
  • 205
  • 1
  • 4