473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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

✓ answered by Dormilich

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

2 1454
Dormilich
8,658 Expert Mod 8TB
have a look at the generated HTML source code, use the name that shows up there.
Nov 12 '11 #2
yer i have sorted it out know thanks, i messed up on the quotation marks!
Nov 12 '11 #3

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

Similar topics

2
by: Randell D. | last post by:
I have a script (below) that can be passed an array and it will dump the contents of the array in to an html table - I use it during development so its nothing sexy. It handles multidimsional...
6
by: Geoff Soper | last post by:
How can I get the name of a variable? i.e. $this_is_a_variable = 10; $variable_name = ????($this_is_a_variable); echo $variable_name; // Displays 'this_is_a_variable' Thanks, Geoff
5
by: Matt Clepper | last post by:
Any way to do this? I need to call functions based on a variable. Do I actually have to make a case statement and call each funciton explicitly, or is there any way to call a function where the...
8
by: Azat | last post by:
Hi, I am wondering if there is a way in C# to get the name of a variable. Let's say: int MyName=3; How can I get a string with the Value "MyName"? Any ideas on that? Thanks
2
by: Christian Blackburn | last post by:
Hi Gang, Can someone show me how to detect the name of the variable received by a procedure? I'd really appreciate it. I would like the following code to detect the name of the strStupid...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
4
by: NeilIanBaker | last post by:
Hello I am trying to select the first name and surname from a name field where the name is in the form of; eg. Mrs Marilyn Payne Mrs Mary Swanton Ms EM Lomas Lt Col R...
9
by: Erwin Moller | last post by:
Hi all, Is it possible (PHP5.2) to find the name of a variable used in the caller of a function from within the function itself? Or to be more clear: ...php code.. $result = foo($abc);...
5
by: monion | last post by:
One more question... I have pulled my query line by line into my php form. Each line/row will have an input field. How can I dynamically assign a variable to the "name" field, for instance if I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.