How do I use a PHP variable in the action attribute?

Discussion in 'PHP' started by stonemikey, Jul 4, 2007.

  1. #1
    Hi,

    I have created a page which includes an HTML form, but I need to make the ACTION attribute a PHP variable so that it can differ depending on something that is set earlier in the page.

    The syntax I am trying is as follows:

    echo( "<form method=\"post\" action=\"$photofile\">" );

    I have tried all sorts of combinations of single and double quotes but can't get anything to work.

    Can anyone help me please?!

    Many thanks in advance for your help.

    Mike
     
    stonemikey, Jul 4, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Your code above should be working. Where does $photofile come from? Is it set? Maybe if you post the rest of your code we can help.

    In the meanwhile you can have a look at this page, where all possibilities on putting variables in strings are listed and explained.

    http://www.php.net/manual/en/language.types.string.php
     
    nico_swd, Jul 4, 2007 IP
  3. webdezzi

    webdezzi Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The line you pasted is correct and it shud work, The problem is with the $photofile variable, its either,

    1. it have no value
    2. it carries the wrong value

    try checking the spelling or paste more of the codes that shows the variable journeying down
     
    webdezzi, Jul 4, 2007 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    Try this one:
    $photofile = "send.php";
    echo( "<form method=\"post\" action=\"".$photofile."\">" );
     
    AsHinE, Jul 4, 2007 IP
  5. stonemikey

    stonemikey Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Disregard this issue. I was being an idiot. The form was created inside a function but the variable was declared outside and not passed in! Doh!
     
    stonemikey, Jul 4, 2007 IP
  6. stonemikey

    stonemikey Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for your replies anyway. Super quick responses!
     
    stonemikey, Jul 4, 2007 IP