1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Get Method / Variable / PHP

Discussion in 'PHP' started by hansab, Apr 3, 2010.

  1. #1
    Hi,

    Please Help.


    Page 1.
    --------------------------
    It has variables defined like
    var1 = 'name'
    var2 = 'email'

    It has a link to contact.html page.


    I want that hyperlink to set this way , so when user reachers contact.html the page is like this

    contact.html?var1=name&var2=email

    Hope you have understood and should be quick for someone knows php, i know it in asp, but dont know how to translate it into php and i am stuck. Please help.


    On Page two.
    ===========
    Just want to print this variables

    I did that through post method, but they are coming from get method, so i want something like querystring.


    Thanks alotttttttttttt in Advance.
     
    hansab, Apr 3, 2010 IP
  2. hansab

    hansab Active Member

    Messages:
    162
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #2
    contact.html was just example, its contact.php actually.
     
    hansab, Apr 3, 2010 IP
  3. ddwebx

    ddwebx Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm not actually sure about what you're trying to accomplish,
    But, if you're trying to get those values using a GET actions instead of POST it's simple :

    
    <?php
    
    $var1 = $_GET['var1']; // gets var1 from the url
    $var2 = $_GET['var2'];// gets var2 from the url
    
    echo "Var 1 :" . $var1 . "<br>Var 2 :" . $var2;
    
    ?>
    
    Code (markup):
    Please let me know if that solved your trouble, if not
    please be more specific I'll try to help you.

    Note 'echo' is a functions similar to 'print' but It's a little bit more faster at the execution time.

    Regards.
     
    ddwebx, Apr 3, 2010 IP
  4. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If page 1 has a form on it just set the target to include the get values you want:

    
    <form action='contact.php?var1=<?echo $name;?>&var2=<?echo $email;?>' method='POST'>
    
    HTML:
     
    Rory M, Apr 3, 2010 IP
  5. waterbomm

    waterbomm Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    in your method must GET
     
    waterbomm, Apr 3, 2010 IP
  6. hansab

    hansab Active Member

    Messages:
    162
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Yes my problem is solved. Thanks alot all of you. You might not have understood my requirement but your posts have given me my answer so thanks :)
     
    hansab, Apr 4, 2010 IP
  7. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Well, if he wants, I was using post in case the second form had long/sensitive values. It would work with both :)
     
    Rory M, Apr 4, 2010 IP