variables in a URL

Discussion in 'PHP' started by FPForum, Mar 24, 2006.

  1. #1
    hello everyone..I am trying to pass some php variables from a form on one of my sites into a URL..although I am having trouble..my form is using post method and the action I am using is to another php file..for example, the script is on bluewidget.com/site1.php

    my action is going to site2.php (same location)

    so I should be hitting a URL like bluewidget.com/site1.php?action=site2.php&name=NameHere&email=EmailHere&submit=Submit

    this should be correct right? Any thoughts or suggestions to a php newb
     
    FPForum, Mar 24, 2006 IP
  2. SpeedyDomainRegistration

    SpeedyDomainRegistration Peon

    Messages:
    170
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you're going to use variables in the url, you'll need to use method=GET on your form.
    POST method will not append vars onto URL.

    To parse the form, you'd use predifined variables $_GET['yourvarname']


    List of all predefined php vars is at http://us3.php.net/manual/en/reserved.variables.php
     
  3. FPForum

    FPForum Notable Member

    Messages:
    4,172
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    225
    Digital Goods:
    2
    #3
    thanks for clearing that up for me Speedy! :)
     
    FPForum, Mar 24, 2006 IP
  4. meikeric

    meikeric Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you're using Post in your form variables in the URL won't work.
    Post and Get are different.

    Ex:
    
    <form action="script.php" method="post">
    Name: <input type="text" name="name" />
    Address: <input type="text" name="address" />
    Phone: Name: <input type="text" name="phone" />
    </form>
    
    Code (markup):
    Then your script will need to be
    
    <?php
    
    $name = $_POST['name'];
    $address = $_POST['address'];
    $phone = $_POST['phone'];
    
    ?>
    
    Code (markup):
    If it's
    
    <form action="script.php" method="get">
    Name: <input type="text" name="name" />
    Address: <input type="text" name="address" />
    Phone: Name: <input type="text" name="phone" />
    </form>
    
    <?php
    
    $name = $_GET['name'];
    $address = $_GET['address'];
    $phone = $_GET['phone'];
    
    ?>
    
    Code (markup):
    If you don't care because people could be sending their forms via Post or Get
    
    <?php
    
    $name = $_REQUEST['name'];
    $address = $_REQUEST['address'];
    $phone = $_REQUEST['phone'];
    
    ?>
    
    Code (markup):
    Hope that helps.
    Mike
     
    meikeric, Mar 24, 2006 IP
  5. FPForum

    FPForum Notable Member

    Messages:
    4,172
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    225
    Digital Goods:
    2
    #5
    Makes total sense..thanks for the excellent explanation Mike!
     
    FPForum, Mar 27, 2006 IP
  6. meikeric

    meikeric Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No prob, let me know if you have anymore quirks.
     
    meikeric, Mar 27, 2006 IP
  7. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you just use hidden inputes of HTML
    review this
    ------------
    step1.php
    <form method="post" action="step2.php">
    <input type="hidden" name="variablename" values="<?=$phpvarible?>">
    </form>
    -------------
    -------------
    step2.php
    u can get the values from $_POST['variblename'];
    -------------
     
    jitesh, Mar 27, 2006 IP