The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

PHP Help

WildEEPWildEEP Registered User regular
edited November 2009 in Help / Advice Forum
Greetings all!

I'm working on a PHP project and we've got to use the GET function and throw values using the URL.

My question is thus:

Can you use variables declared in the php to populate the values on URL?

Example:

$Variablename1 = 20 * $othervariable

<a href="random.php?throwvalue=$Variablename1">

Something like that?

Then I just make a GET command for throwvalue?
If its possible, whats the syntax? I've experimented but come up with nothing.

Thanks in advance!

WildEEP on

Posts

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    edited November 2009
    The problem is $Variablename1 is being interpreted literally. You need the PHP code to interpret it:

    <a href="random.php?throwvalue=<?=$Variablename1>">

    Should work.

    admanb on
  • SeguerSeguer of the Void Sydney, AustraliaRegistered User regular
    edited November 2009
    admanb wrote: »
    The problem is $Variablename1 is being interpreted literally. You need the PHP code to interpret it:
    <a href="random.php?throwvalue=<?php echo $Variablename1; ?>">
    

    Should work.

    Fixed that for you.

    OP: You should probably come up with some sort of standard for variable names (eg camelCase).


    NINJA EDIT: You might want to take a look at url encode, depending on what the values of the variables are.

    Seguer on
  • ResonantResonant Registered User regular
    edited November 2009
    Seguer wrote: »
    Fixed that for you.

    OP: You should probably come up with some sort of standard for variable names (eg camelCase).


    NINJA EDIT: You might want to take a look at url encode, depending on what the values of the variables are.

    Technically, the following will work just fine:
    <a href="random.php?throwvalue=<?=$Variablename1>">
    

    <?= ... > is a short tag that will be interpreted as <?php echo ... > But short_open_tag must be enabled in php.ini. It's generally good practice to always write out your opening php tags instead of using the short open tag. It allows for maximum compatibility in case a server has short_open_tag turned off.

    Resonant on
    convergesig.jpg
  • SeguerSeguer of the Void Sydney, AustraliaRegistered User regular
    edited November 2009
    Resonant wrote: »
    Technically, the following will work just fine:
    <a href="random.php?throwvalue=<?=$Variablename1>">
    

    <?= ... > is a short tag that will be interpreted as <?php echo ... > But short_open_tag must be enabled in php.ini. It's generally good practice to always write out your opening php tags instead of using the short open tag. It allows for maximum compatibility in case a server has short_open_tag turned off.
    This has been gone over in another thread :P

    Seguer on
Sign In or Register to comment.