Problem with passing variables

Discussion in 'PHP' started by HoraceMiles, Mar 2, 2007.

  1. #1
    Hi again I am new to PHP and I am having an issue passing a variable to another page using the header method.

    Here is the code I am dealing with:

    I am getting user input and then sending it to a serverapi and recieving a numerical value back.. This all works I am then trying to send the value returned to another page to be used there.

    $to = "http://www.mydomain.com/mypage.php?rmid="+'$rmid';

    header('Location: '. $to);
    exit;

    The url I get is:

    http://www.mydomain.com/0

    If I use the following:
    $to = 'http://www.mydomain.com/mypage.php?rmid=+$rmid';

    I get:

    http://www.mydomain.com/mypage.php?rmid=$rmid

    Can any tell me what I am doing wrong here.

    Also if anyone can tell me how I can combine the values of two text strings in php. i.e. a$= txt1 " " txt2 seems to be giving me problems as well

    Thank you ahead of time whomever you are..


    Miles
     
    HoraceMiles, Mar 2, 2007 IP
  2. thedark

    thedark Well-Known Member

    Messages:
    1,346
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    168
    Digital Goods:
    1
    #2
    if you use single quotes ' and ' the variables will be used with their names, not with their values. If you use double quotes, variables will be replaced with their values, but the best way to do this, is to put variables separately, example:

    $to = "http://www.somewebsite.com/". $variable;

    The operator for concatenation in php is . ( dot ) .

    $to = $text1 . " " . $text2;


    For more examples use http://www.php.net
     
    thedark, Mar 2, 2007 IP
  3. HoraceMiles

    HoraceMiles Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your prompt reply. It is most appreciated...

    Miles
    New to PHP
     
    HoraceMiles, Mar 2, 2007 IP
  4. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $to = "http://www.mydomain.com/mypage.php?rmid=".$rmid;

    header('Location: '. $to);
    exit
     
    jitesh, Mar 14, 2007 IP