rvdb86 Posted October 6, 2009 Share Posted October 6, 2009 Hi, I have a list of check box options that is generated from the database. I need to insert values into a table only if they have been selected by the user. each name of the check boxes starts with area and then the id. eg: area1, area2 etc.. I am pretty sure i need a for loop I'm just not to sure about the format. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/ Share on other sites More sharing options...
bcode Posted October 6, 2009 Share Posted October 6, 2009 if(isset($POST[area1]){ run code here } Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931854 Share on other sites More sharing options...
rvdb86 Posted October 6, 2009 Author Share Posted October 6, 2009 thanks for the reply but maybe i did not explain the problem properly. Because the list of check boxes is generated from a database I do not know how many options the user will have. therefore I cannot use the following code: if (isset(area1)){ code } if (isset(area2)){ code } I think I need to create an array of all the $_POST variables that start with area and then insert their values. Again this is a guess and I may be wrong. However I hope the problem is clearer now. Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931865 Share on other sites More sharing options...
Jnerocorp Posted October 6, 2009 Share Posted October 6, 2009 How many areas are there to chose from? -John Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931867 Share on other sites More sharing options...
rvdb86 Posted October 6, 2009 Author Share Posted October 6, 2009 I don't know how many areas there will be as the user will be able to add and remove areas from the database. Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931876 Share on other sites More sharing options...
mikesta707 Posted October 6, 2009 Share Posted October 6, 2009 what do your checkboxes look like? they should be of the format <input type="checkbox" name="boxes[]" value="something" />clicky <input type="checkbox" name="boxes[]" value="somethingelse" />clicky1 <input type="checkbox" name="boxes[]" value="athirdvalue" />clicky2 when you submit a checkbox, on the values that were selected will be in the $_POST['boxes'] array. Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931883 Share on other sites More sharing options...
Jnerocorp Posted October 6, 2009 Share Posted October 6, 2009 and on the processing page you would put: $boxes = $_POST['boxes']; foreach ($boxes as $b) { echo $b."<br />"; } Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931906 Share on other sites More sharing options...
rvdb86 Posted October 6, 2009 Author Share Posted October 6, 2009 Great guys it works a treat Link to comment https://forums.phpfreaks.com/topic/176742-solved-insert-into-db-only-is-isset/#findComment-931916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.