How to set the name field in a HTML tag as a PHP variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ollie Shotton
    New Member
    • Jan 2011
    • 12

    How to set the name field in a HTML tag as a PHP variable?

    i have this code here (simplified it a bit for this but you get the idea!) and i have assigned the name field of a select tag with a value of a variable so that when i click the Update button i can use _POST[name_var] to get the value of the select. however this returns the following error:

    "Notice: Undefined index: 62"

    if i manually put 62 in the name field and in the _POST[62] it does work so there is no problem with the rest of my code.

    if anyone could tell me what i need to do to make this work i would be greatly appreciative!

    Thanks in advance
    Ollie

    Code:
    //role.php file
    <?php
    $name_var = 62;
    
    echo '<form method="POST" action="update_role.php">';
    
    echo '<select id="dropdown" name=$name_var>';
    //option tags in here...
    echo '</select>';
    
    echo '<input type="submit" name="btn_update" id="button" value="Update" />';
    echo '</form>';
    ?>
    
    //update_role.php file
    <?php
    $name_var = 62;
    $getVar = _POST[$name_var];
    ?>
    Last edited by Ollie Shotton; Nov 11 '11, 03:14 PM. Reason: code little wrong! :P
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    have a look at the generated HTML source code, use the name that shows up there.

    Comment

    • Ollie Shotton
      New Member
      • Jan 2011
      • 12

      #3
      yer i have sorted it out know thanks, i messed up on the quotation marks!

      Comment

      Working...