Re: [PHP] Making variables with an iteration? STILL
Hello Robert, Monday, December 6, 2004, 3:55:21 PM, you wrote: RS snip RS ?php RS for ($i=1; $i10; $i++) RS { RS if (isset ($_POST['choice'.$i])) RS { RSfor ($j=1; $j5; $j++) RS{ RS $tempChoice = choice . $j; RS $$tempChoice = $_POST['choice'.$i]; RS} RS } RS } RSecho $choice1; RSecho $choice2; RSecho $choice3; RSecho $choice4; ? RS /snip RS The problem seems to be that it is only doing this on the last one, no matter RS which one it is... I know it is in the iterations, but I can't place my finger RS on where I need to change things up. Why not just use extract() on the $_POST values with a pre-defined list of variables and use the EXTR_IF_EXISTS option to make it more secure? Best regards, Richard Davey -- http://www.launchcode.co.uk - PHP Development Services I am not young enough to know everything. - Oscar Wilde -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Making variables with an iteration? STILL
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 06 December 2004 15:55, Robert Sossomon wrote: Here's the full code and the driving page: http://rsossam-lap.ces.ncsu.edu/leadership/test.html snip ?php for ($i=1; $i10; $i++) { if (isset ($_POST['choice'.$i])) { for ($j=1; $j5; $j++) { $tempChoice = choice . $j; $$tempChoice = $_POST['choice'.$i]; } } } echo $choice1; echo $choice2; echo $choice3; echo $choice4; /snip You've got too many iterators in there. With $i=1, if $_POST['choice1'] is set: you set $choice1 to the value of $_POST['choice1']. With $i=2, if $_POST['choice2'] is set: you set $choice1 to the value of $_POST['choice2'], then you set $choice2 to the value of $_POST['choice2']. With $i=3, if $_POST['choice3'] is set: you set $choice1 to the value of $_POST['choice3'], then you set $choice2 to the value of $_POST['choice3'], then you set $choice3 to the value of $_POST['choice3']. Etc. Within your PHP script, I'd strongly recommend using an array, even if you don't name your HTML form variables as array elements (which is actually very easy, despite what a lot of people seem to think). Then your code just needs to look like this: for ($i=1; $i10; $i++) { if (isset($_POST['choice'.$i])) { $choice[$i] = $_POST['choice'.$i]; } } foreach ($choice as $one_choice) { echo $one_choice; } Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making variables with an iteration? STILL
I think you can use the export() function for that.. Here's the full code and the driving page: http://rsossam-lap.ces.ncsu.edu/leadership/test.html snip ?php for ($i=1; $i10; $i++) { if (isset ($_POST['choice'.$i])) { for ($j=1; $j5; $j++) { $tempChoice = choice . $j; $$tempChoice = $_POST['choice'.$i]; } } } echo $choice1; echo $choice2; echo $choice3; echo $choice4; ? /snip The problem seems to be that it is only doing this on the last one, no matter which one it is... I know it is in the iterations, but I can't place my finger on where I need to change things up. -- Robert Sossomon, Business and Technology Application Technician 4-H Youth Development Department 200 Ricks Hall, Campus Box 7606 N.C. State University Raleigh NC 27695-7606 Phone: 919/515-8474 Fax: 919/515-7812 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making variables with an iteration? STILL
Thomas Munz wrote: I think you can use the export() function for that.. He probably means http://php.net/extract but that defeats the purpose of turning register_globals OFF and is BAD SECURITY. Here's the full code and the driving page: http://rsossam-lap.ces.ncsu.edu/leadership/test.html snip ?php for ($i=1; $i10; $i++) { if (isset ($_POST['choice'.$i])) { for ($j=1; $j5; $j++) { $tempChoice = choice . $j; $$tempChoice = $_POST['choice'.$i]; } } } Work out what this does by hand, step by step: $i $j 1 1 $tempChoice = 'choice1'; $choice1 = $_POST['choice1']; 1 2 $tempChoice = 'choice2'; $choice2 = $_POST['choice1']; 1 3 $tempChoice = 'choice3'; $choice3 = $_POST['choice1']; 1 4 $tempChoice = 'choice4'; $choice4 = $_POST['choice1']; 1 5 $tempChoice = 'choice5'; $choice5 = $_POST['choice1']; 2 1 $tempChoice = 'choice1'; $choice1 = $_POST['choice2']; 2 2 $tempChoice = 'choice2'; $choice2 = $_POST['choice2']; 2 3 $tempChoice = 'choice3'; $choice3 = $_POST['choice2']; 2 4 $tempChoice = 'choice4'; $choice4 = $_POST['choice2']; 2 5 $tempChoice = 'choice5'; $choice5 = $_POST['choice2']; . . . Is that what you want? echo $choice1; echo $choice2; echo $choice3; echo $choice4; ? /snip The problem seems to be that it is only doing this on the last one, no matter which one it is... I know it is in the iterations, but I can't place my finger on where I need to change things up. -- Robert Sossomon, Business and Technology Application Technician 4-H Youth Development Department 200 Ricks Hall, Campus Box 7606 N.C. State University Raleigh NC 27695-7606 Phone: 919/515-8474 Fax: 919/515-7812 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php