Hi guys, I’m just new to php language and needs your expertise here. I wanted to add a hyperlink in a variable ($varible1) in index.php and pass the value of the $variable1 to another variable ($variable2) in another php file. Can you please show me how to do it?
Thanks a lot…

    To pass values through the url (hyperlink) you will form it as:

    http://www.domain.com/page.php?key=value

    Now, you get the variable in a PHP page by using:

    $var = $_GET['key'];

    So, here's the gist:

    <?php
    
    echo "<a href='http://www.domain.com/page.php?id=5'>Next Page</a>";
    
    ?>
    
    Page.php
    <?php
    
    $id = $_GET['id'];
    
    echo "The ID is: ".$id;
    
    ?>

    That will ouput:

    The ID is: 5

    ~Brett

      i got an error:

      Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in page2.php on line 234

      here's the code in index.php
      <a target="_blank" href='./page2.php?variable2=$variable1'><td bgcolor=\"#99ccff\"><font face=Arial size=2>$variable2</font></a></td>

      what is wrong with this why am getting an error?

      thanks....

        Originally posted by dreaddlord
        <a target="_blank" href='./page2.php?variable2=$variable1'><td bgcolor=\"#99ccff\"><font face=Arial size=2>$variable2</font></a></td>

        Why are you escaping some of the double quotes, but not all? Also, why are you passing $variable1 to page2.php, but passing it as 'variable2'? And why is your anchor tag not inside the <td> tag?

        Assuming you're trying to echo the line above, it should be

         echo "<td bgcolor='#99ccff'><a target='_blank' href='./page2.php?variable2=" . $variable1 . "'><font face='Arial' size='2'>" . $variable2 . "</font></a></td>";

        Also, your error was reported in page2.php. You'll have to post the code for that page before we can guess why you're getting a parse error.

          here's added information

          Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in index.php on line 234

          index.php

          <td bgcolor=\"#99ccff\"><a target="_blank" href='./page2.php?variable2=".$variable1."'><font face=Arial size=2>$variable1</font></a></td>

          page2.php

          $variable2 = $_GET['variable2'];
          $sqldetails1="select * from table1 where name='".$variable2."'";

            Your missing a closing ";" on an echo statement somewhere is my guess. Giving us only small bits of your line(s) don't help. If you ask for help, COPY & PASTE your code here, and put a comment as to what line is 234.

            ~Brett

              thank you guys for giving your ideas and suggestions....
              i have finally made it worked...

              think i got the error from here:
              <a target="_blank" href='./page2.php?variable2=$variable1'>
              double quotes didn't worked...

              anyway, all your suggestions helps...
              thanks again..

                i want to modify the window for the page2.php

                how can i add popup window for this code?

                <a target='_blank' href='./page2.php?variable2=".$variable1."'>$variable1></a>

                please help me with this.....

                  is it possible to use javascript popup window in a php codes....???

                  can you please show me how to do it???

                    is this being echo'd <a target="_blank" href='./page2.php?variable2=$variable1'>

                    If so you need \"_blank\" not just "_blank"

                    Unless it has been changed in php5 😉

                      It's deffinately possible.

                      <?php 
                      //what you want your colde to be here
                      
                      echo "<script language=javascript>";
                      echo "CONTENTS OF THE JAVASCRIPT HERE";
                      echo "</script>";
                      

                      Now, there are a couple other ways, but just give this a try and see what you get..

                        I have a related question to this one.

                        I have a site that I'm working on where I have a global variable in the main link for affiliate accounts where the page is set up like this:

                        http://www.url.com/?site_id=12345

                        That triggers the variable $linktext2

                        $linktext2 = "&site_id=$site_id";

                        I have been able to pass the variable to every other url on the page except for the one dynamically created in this function:

                        function makePageLink($pageNum,$linkTitle="") { 
                        $pageName="page.php"; 
                        $link= "<a class=blue href=\"".$pageName; 
                        $link.= "?page=" .$pageNum;
                        $link.= $linktext2;
                        $link.= "\">"; 
                        if ($linkTitle != "") { 
                        $link .= $linkTitle; 
                        } else { 
                        $link .= $pageNum; 
                        } 
                        $link.= "</a>"; 
                        return $link; 
                        } 

                        If I echo that value before and after the function it prints the variable just fine, just not during. Any thoughts?

                        Ian

                          This is a variable scope issue. Functions are only aware of global variables and variables they have been passed. So if you want your function to know about $linktext2 you'll need to either pass it to the function or declare it to be global within the function like:

                          global $linktext2;

                            Originally posted by kburger
                            This is a variable scope issue. Functions are only aware of global variables and variables they have been passed. So if you want your function to know about $linktext2 you'll need to either pass it to the function or declare it to be global within the function like:

                            global $linktext2;

                            [/B]

                            That worked perfectly. Thank you kburger!

                            Ian

                              Write a Reply...