web design/PHP Help, sending a variable through a form

Discussion in 'OT Technology' started by Moscowmetro, Jul 26, 2005.

  1. Moscowmetro

    Moscowmetro New Member

    Joined:
    Mar 31, 2004
    Messages:
    1,378
    Likes Received:
    0
    Hello,
    A web visitor clicks a hyperlink with id="Test" name="pdf"
    the link -> ../downloads/downloadform.php?id=Test

    The user then goes to said form page (downloadform.php) and fills out a basic web form that stores variables and sends an email using PHP.

    Using javascript on the onLoad event of the submit button, i send the user to the "thank you page" where they can then download the pdf they clicked (called Test).

    The PHP code on the thank you page - >
    <?php
    $pdf = $_GET['id'];
    ?>
    But the variable is not getting passed to the hyperlink ->
    <a href="../<? echo $pdf; ?>">

    The link shows up without the word "test" in the path BUT on the url bar, Test is shown as id=Test?

    help?
     
  2. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    if it is showing up as page.php?id=test there wont be a $_GET[] variable, it is going to be $id.

    Pretty sure what you want is $pdf = $id
     
  3. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    WRONG.

    That requires "register_globals = true" which is a HORRIBLE way to code. The $_GET[] variable is a server-based array containing address-passed variables. Check your case.
     
  4. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    how the hell is it that I can spend 3 months learning how to code php and never see this come up?

    Seriously I never liked how variables were handled in that sense. I feel like I have been cheated :o
     
  5. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    yeah. our 1st year web design course goes right into OOP for PHP5
     
  6. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Variables SHOULD be handled without registered_globals turned on.
     
  7. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Oh, yeah, and you need to use the $_POST global array since the data is coming from a form. $_GET is used for data access through URL strings, $_POST is used to access data from variables which were set by forms.

    PHP:
    echo "<a href=\"../downloads/downloadform.php?id=$_POST['id']\">Download</a>";
    Now, if you're going to use this, the variable "id" MUST be set by the form. How are you generating the ID? Well, whatever you do to obtain the ID, you can just toss it in a hidden form.

    PHP:
    <input type="hidden" name="id" value="<?=$id?>" />
     

Share This Page