By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

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

P: 12
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

Expand|Select|Wrap|Line Numbers
  1. //role.php file
  2. <?php
  3. $name_var = 62;
  5. echo '<form method="POST" action="update_role.php">';
  7. echo '<select id="dropdown" name=$name_var>';
  8. //option tags in here...
  9. echo '</select>';
  11. echo '<input type="submit" name="btn_update" id="button" value="Update" />';
  12. echo '</form>';
  13. ?>
  15. //update_role.php file
  16. <?php
  17. $name_var = 62;
  18. $getVar = _POST[$name_var];
  19. ?>
Nov 11 '11 #1

✓ answered by Dormilich

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

Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 8,639
have a look at the generated HTML source code, use the name that shows up there.
Nov 12 '11 #2

P: 12
yer i have sorted it out know thanks, i messed up on the quotation marks!
Nov 12 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.