dcparham Posted February 21, 2009 Share Posted February 21, 2009 searched miles of links, some on this forum, nothing seems to answer this simple question: [using php5 and mySQL backend, dynamically building multiple groups of radio buttons.] each radio button is named with an array variable name, and its value is an a variable. --->when i submit the form, how do i retrieve the value of the selected radio button?<--- you'll note in radio1.php, $arrCategory[$i] value is "gender." so in radio2.php if i capture $_POST['gender']; it does so easily. however, i need to capture the radio buttons which exist only with variable names. so, radio2.php needs to collect only the radio buttons selected, and its value. if the answer is given, i can apply to the larger app: //this is radio1.php; passes control to radio2.php <html> <head><title></title></head> <body> <form name ="form1" method ="post" action ="radio2.php"> <?php $arrCategory=array(2); $arrValue=array(2); $i=0; $j=1; $arrCategory[$i]='gender'; $arrValue[$i]='[XY]'; $arrValue[$j]='[XX]'; echo("<input type='radio' name='".$arrCategory[$i]."' value='".$arrValue[$i]."'>XY"); echo("<input type='radio' name='".$arrCategory[$i]."' value='".$arrValue[$j]."'>XX"); ?> <Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button"> </form></body></html> //this is radio2.php <html> <head><title></title></head> <body> <?PHP echo $_POST['gender']; //###THIS WORKS //echo $_POST['$arrCategory[$i]']; //###THIS DOES NOT WORK. ?> </body> </html> HELP PLEASE? many many hours with this so far. [converting an ASP app that already handles this scenario fine.] Link to comment https://forums.phpfreaks.com/topic/146193-how-do-i-pass-a-radio-button-name-that-is-an-array-variable-to-next-page/ Share on other sites More sharing options...
samshel Posted February 21, 2009 Share Posted February 21, 2009 is this complete code ? in radio2.php, where are you defining $arrCategory and $i ? Link to comment https://forums.phpfreaks.com/topic/146193-how-do-i-pass-a-radio-button-name-that-is-an-array-variable-to-next-page/#findComment-767538 Share on other sites More sharing options...
dcparham Posted February 23, 2009 Author Share Posted February 23, 2009 thx, samshel - point taken; say $1=0;. still an error. if we were to start even simpler[not using an array, but simply a variable], say on radio1.php the radio was defined as follows[showing the operative stmts]: ---radio1.php...> $arrCategory='gender'; $arrValue='[XY]'; echo("<input type='radio' name='".$arrCategory."' value='".$arrValue."'>XY"); <--- --- and radio2.php...> echo $_POST['$arrCategory']; <--- [still yet...] ERRMSG: Notice: Undefined index: $arrCategory in C:\Inetpub\wwwroot\survey\radio2.php on line 7 PHP Notice: Undefined index: $arrCategory in C:\Inetpub\wwwroot\survey\radio2.php on line 7 *[so, same concept - PHP not passing radio variable names passing to next page.]* SamShel, thx mucho for your time and effort - really really would like a breakthrough; utilizing 2MUCH time on this ["can't sleep" until the working-ASP project is converted to PHP and mySQL!] Link to comment https://forums.phpfreaks.com/topic/146193-how-do-i-pass-a-radio-button-name-that-is-an-array-variable-to-next-page/#findComment-768866 Share on other sites More sharing options...
samshel Posted February 23, 2009 Share Posted February 23, 2009 1) u need $i not $1 2) u need to define $arrCategory also on radio2.php. if you are getting value of $_POST['gender']; properly, that means posting is working properly ! Link to comment https://forums.phpfreaks.com/topic/146193-how-do-i-pass-a-radio-button-name-that-is-an-array-variable-to-next-page/#findComment-769530 Share on other sites More sharing options...
dcparham Posted February 24, 2009 Author Share Posted February 24, 2009 Thank you, SamShel - u r right, i meant "i". so, yes the post is working, but the mystery is how from radio2.php page, to receive the post of a radio button whose original name was generated by a variable name; the variable name might be 'gender', but it never looks like that on page1, because 'gender' is the value drawn from a mysql table. this is the actual stmt: "echo("<tr><td width='20px'><input type='radio' name='".$row['var1']."' value='".$row['surveyTopic']."'></td>");" so, how can i from page2, get the value selected by receiving the post of a variable name? i did not withhold the original code to be difficult, because the concept is basically how to receive the value of each of possibly multiple radio buttons chosen. i.e., the radios from which to choose are part of a survey, like this: [category] ACCOUNTING [radio"ACCOUNTING"]> How to file check requests [radio"ACCOUNTING"]> Filing Expense Reimbursements [category] HR [radio "HR"]> Communication Skills [radio "HR"]> Time Management Skills [radio "HR"]> Reducing Stress in the Workplace etc... and each set of radio buttons are named by a query value, $row['var1'], which is the result of a mysql stmt: $sql_1 = "SELECT DISTINCT(surveyCategory) as var1 FROM surveyTopics GROUP BY surveyCategory;"; so, now from page2, how do i $_POST['$row['var1']']? you are the only one responding, i really appreciate it! i just feel like i am missing something and have been looking into ISSET function to try and capture, at the submit, the radios which are chosen, and what each value is from each radio if it is chosen. Link to comment https://forums.phpfreaks.com/topic/146193-how-do-i-pass-a-radio-button-name-that-is-an-array-variable-to-next-page/#findComment-769756 Share on other sites More sharing options...
samshel Posted February 24, 2009 Share Posted February 24, 2009 it does not make any difference if radio button names are variable or static. when HTML is redered u will see them as static for example "gender". on second page, you will need to getch the data again from mysql table and loop through the rows to see if $_POST[$row['var1']] is set. if u r not able to make it send me complete code files, i will take a look. Link to comment https://forums.phpfreaks.com/topic/146193-how-do-i-pass-a-radio-button-name-that-is-an-array-variable-to-next-page/#findComment-770542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.