SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using an a href with php code

    Code:
    <?php
        $id = 5;
        session_start();
        function fn1(){
    		//code
    		return "http://www.philosophaie.heliohost.org/Julian_Date.php?"&data=$id";
        }
        session_write_close();
    ?>
    
    
    <a href = "<?php echo fn1(); ?>">Text</a>
    The a href does not work and I keep getting:

    Code:
    %34http://www.philosophaie.heliohost.org/Julian_Date.php?"&data=5
    on the link mouseover. How do I remove the %34 to execute the link?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The end of your string is the problem, see the below which I've highlighted in red to show the problem.

    Code:
    Julian_Date.php?"&data=$id";
    There is no reason to have the double quotes there as well as the ampersand after the double quote as your creating an improperly formatted URL, if you need to at any point use symbols and such in a URL you need to use the urlencode() function.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was really:

    return "http://www.philosophaie.heliohost.org/Julian_Date.php?sec=$urladd"."&data=$id";
    and I still got the %34 error.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    You have to pass the $id to the function, because is defined outside the function. Try this code:
    Code:
    <?php
    $id = 5;
    session_start();
    function fn1($id){
      //code
      return "http://www.philosophaie.heliohost.org/Julian_Date.php?&data=$id";
    }
    session_write_close();
    ?>
    
    <a href = "<?php echo fn1($id); ?>">Text</a>
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •