gple Posted March 11, 2007 Share Posted March 11, 2007 I am using 15 text areas for the user to put in 15 names. so we have user1, user2,....user15. How can I do this below: $user1=$_POST['user1']; $user2=$_POST['user2']; $user3=$_POST['user3']; $user4=$_POST['user4']; $user5=$_POST['user5']; $user6=$_POST['user6']; to input the data in a table without actually having to type out 15 lines. Link to comment https://forums.phpfreaks.com/topic/42175-help-with-form-post/ Share on other sites More sharing options...
tauchai83 Posted March 11, 2007 Share Posted March 11, 2007 hehe. No so much shortcut here. 15 lines only is good. I'm not sure it is possible to make it less than 15 liens with shorter php code. But it doesn't matter as the most important is it pass the value and could be saved into DB. Link to comment https://forums.phpfreaks.com/topic/42175-help-with-form-post/#findComment-204595 Share on other sites More sharing options...
fert Posted March 11, 2007 Share Posted March 11, 2007 http://us2.php.net/manual/en/function.extract.php Link to comment https://forums.phpfreaks.com/topic/42175-help-with-form-post/#findComment-204598 Share on other sites More sharing options...
tauchai83 Posted March 11, 2007 Share Posted March 11, 2007 Warning Do not use extract() on untrusted data, like user-input....... qoute from php manual. Link to comment https://forums.phpfreaks.com/topic/42175-help-with-form-post/#findComment-204601 Share on other sites More sharing options...
chronister Posted March 11, 2007 Share Posted March 11, 2007 Try something like this. I cannot test it right now as my stupid testing server is not wanting to respond properly. <?php $x=1; while($x < 16){ $user.$x=$_POST["user.$x"]; $x++; } ?> Link to comment https://forums.phpfreaks.com/topic/42175-help-with-form-post/#findComment-204604 Share on other sites More sharing options...
per1os Posted March 11, 2007 Share Posted March 11, 2007 foreach ($_POST as $key => $val) { if (ereg($key, "user")) { $$key = $val; } } What the $$key does is if $key = user1 it sets the variable name to user1, IE: $user1 now contains $val. --FrosT Link to comment https://forums.phpfreaks.com/topic/42175-help-with-form-post/#findComment-204613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.