shadiadiph Posted December 10, 2008 Share Posted December 10, 2008 Is there anyway of collecting the variables submitted by a form and renaming them. Problem is they all have the same name with a number afterthem example ver0 ver1 ver2 ver3 ver4 to ver10 but there is no way of knowing which of these variables have been submitted?? Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/ Share on other sites More sharing options...
Maq Posted December 10, 2008 Share Posted December 10, 2008 Here's how to grab all of the posts and print the name of the variable (notice the double $$) and value. foreach ($_POST as $key => $value) { echo "Name of var: " . $$key . " value: " . $value; } Hope this helps. * You should have posted this in PHP Help not Regex unless someone has a regex answer... Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-710990 Share on other sites More sharing options...
MadTechie Posted December 10, 2008 Share Posted December 10, 2008 Worth noting.. if on the form you use a name with square brackets it will work as an array ie <input type="test" name="test[]"> <?php echo "found ".count($_POST['test']); print_r($_POST['test']) ?> Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711006 Share on other sites More sharing options...
Maq Posted December 10, 2008 Share Posted December 10, 2008 Is there anyway of collecting the variables submitted by a form and renaming them. Yes, if you post the form code we could give you a better answer. Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711014 Share on other sites More sharing options...
shadiadiph Posted December 10, 2008 Author Share Posted December 10, 2008 sorry i thought i had posted in php help my problem is this row echo '<tr><td><input type="checkbox" name="news'.$i.'" value="'. $mtitle. '" /></td><td width="90% align="left">'. $mtitle. '</td></tr>'; $i++; } when it posts there are 20 choices to choose from and the select values come out as new0 to news20 so on my submit form it is impossible know which valiue to put in the ($HTTP_POST_VARS[" "]); section as the values change each time the form is submitted. I have been working this for more than 20 hours now and to no avail I am thinking there is a simple solution like maybe an onselct function name='' else name= on the form this is driving me nuts. Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711031 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 echo '<tr><td><input type="checkbox" name="news[]" value="'. $mtitle. '" /></td><td width="90% align="left">'. $mtitle. '</td></tr>'; $i++; } That will put it in an array and $HTTP_POST_VARS is depreciated, use $_POST instead. This will return an array of news items, so $_POST['news'][0] will give you the first item etc. Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711076 Share on other sites More sharing options...
shadiadiph Posted December 10, 2008 Author Share Posted December 10, 2008 Almost right worked posted to the database but each news field in the database just had Array added to it? Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711092 Share on other sites More sharing options...
shadiadiph Posted December 10, 2008 Author Share Posted December 10, 2008 sorry man that is awesome i have just been awake for 30 hours playing with this i was so close many times i feel like a real idot. Thanks that is awesom thank you very very much premiso Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711103 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 Worth noting.. if on the form you use a name with square brackets it will work as an array ie <input type="test" name="test[]"> <?php echo "found ".count($_POST['test']); print_r($_POST['test']) ?> Honestly, this was solved 3-4 posts ago. I was just re-iterating that point. Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711106 Share on other sites More sharing options...
shadiadiph Posted December 10, 2008 Author Share Posted December 10, 2008 mm i guess it was thanks anyway your version was easier for me after 30 hours of no sleep to comprehend cheers once again Quote Link to comment https://forums.phpfreaks.com/topic/136288-solved-colllecting-unknown-varial-names-and-changing-them/#findComment-711114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.