john_6767 Posted June 26, 2006 Share Posted June 26, 2006 ok, i'm trying to get multiple checkboxes going and i think i have everything sorted except i cannot check to see if the checkbox is checked, the checkboxes are dynamic so i cannot type in the name as it changes so what i was trying to do is //start loopif (isset($_POST['checkboxName_$variable'])) {//add checkbox to database}//end loopwhere $variable is a number i put after every checkbox to make them unique. So why isn't it working (is it due to having a variable in the post['']) and how could i do the checkbox check differently?Also my logic for this system above is that a checkbox only comes trhough if it is checked, and i add it to the db if checkbox is checked but not if not checked. Anyone see any potential problems,cheers Quote Link to comment https://forums.phpfreaks.com/topic/12899-a-variable-within-_post-possible/ Share on other sites More sharing options...
john_6767 Posted June 28, 2006 Author Share Posted June 28, 2006 any idea guys? this is driving me nuts Quote Link to comment https://forums.phpfreaks.com/topic/12899-a-variable-within-_post-possible/#findComment-50295 Share on other sites More sharing options...
Zane Posted June 28, 2006 Share Posted June 28, 2006 how are you naming them again........?is the name so dynamic that you can't create the same ....[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][i]dynaminity[/i][!--colorc--][/span][!--/colorc--]....to create the validation?I hope that made senseI'm really tired Quote Link to comment https://forums.phpfreaks.com/topic/12899-a-variable-within-_post-possible/#findComment-50325 Share on other sites More sharing options...
wdo_will Posted July 2, 2006 Share Posted July 2, 2006 It is possible with any other array, so I'm sure it will work here.The problem is that variables are only read within double quotes ("$var"). So, if you make $var = 'hi', and say echo '$var'; it will not work. But if you say echo "$var"; or echo $var; it will work.So, basicly, there are three ways to do this.[code]<?php //start loopif (isset($_POST['checkboxName_'.$variable])) {//add checkbox to database}//end loop?[/code]This will make the variable out of the $_POST array have two strings, ie 'checkboxName_' and then $variable (hope that makes sense :-\)[code]<?php //start loopif (isset($_POST["checkboxName_$variable"])) {//add checkbox to database}//end loop?[/code]This does the same as your example, but actually reads the variable.[code]<?php //start loop$var = "checkboxName_$variable";if (isset($_POST[$var])) {//add checkbox to database}//end loop?[/code]This puts the entire sting that you want to grab out of the $_POST array into a variable.I hope you can understand this post, I can't think of how to explain everything properly! Quote Link to comment https://forums.phpfreaks.com/topic/12899-a-variable-within-_post-possible/#findComment-52210 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.