brodywx Posted March 7, 2007 Share Posted March 7, 2007 I have an array of checkboxes. When the user submits the form I'm trying to find out which checkboxes are selected. I'm grabbing them through the $_POST variable, but it's not working. If my checkbox array has the name chkArr[someValue], then why can't I use this statement to get it's value: $_POST['chkArr[someValue]'] ??? Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/ Share on other sites More sharing options...
willpower Posted March 7, 2007 Share Posted March 7, 2007 post your form and php Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202036 Share on other sites More sharing options...
effigy Posted March 7, 2007 Share Posted March 7, 2007 $_POST[chkArr][someValue] Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202038 Share on other sites More sharing options...
brodywx Posted March 7, 2007 Author Share Posted March 7, 2007 Here's a snippet from my form. It loops a bunch of times creating checkboxes like so: <input type=checkbox name=filterItem[".$in_row[ProfileGroup]."] id=\"fi".$in_row[ProfileGroup]."\" ".$chk." onclick=\"javascript:SetChecked(this,'filterItem[".$in_row[ProfileID]."]')\"> <font size=-1><label for=\"fi".$in_row[ProfileGroup]."\"><b>".$in_row[ProfileGroup]."</b></label></font> I'm testing this statement to see if I can't determine which checkboxes are check: echo $_POST['filterItem['.$itemsArray[0].']']; RIght now it doesn't output anything, even though $itemsArray has values in it. Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202042 Share on other sites More sharing options...
kenrbnsn Posted March 7, 2007 Share Posted March 7, 2007 At the start of the processing script, put in this line: <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> This will dump the contents of the $_POST array to your screen. Then you should be able to figure out how to reference the items. Ken Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202045 Share on other sites More sharing options...
boo_lolly Posted March 7, 2007 Share Posted March 7, 2007 this is an example of how i do it: <?php if($_POST['delete'] != NULL){ foreach($_POST['delete'] as $key => $val){ $sql = "DELETE FROM your_table WHERE id = '". $val ."'"; mysql_query($sql) OR die ("The query:<br>" . $sql . "<br>Caused the following error:<br>\t". mysql_error()); } } $sql = "SELECT * FROM your_table"; $query = mysql_query($sql); echo "<form action=\"\" method=\"post\">\n"; while($row = mysql_fetch_array($query)){ echo $row['name'] ."<input type=\"checkbox\" name=\"delete[]\" value=\"". $row['id'] ."\"><br />\n"; } echo "</form>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202048 Share on other sites More sharing options...
pocobueno1388 Posted March 7, 2007 Share Posted March 7, 2007 <?php if ($_POST['submit']){ $checked_boxes = $_POST['array_name']; $num = count($checked_boxes); for($i = 0; $i < $num; $i++){ $checked = $checked_boxes[$i]; echo "$checked[$i]<br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202049 Share on other sites More sharing options...
brodywx Posted March 7, 2007 Author Share Posted March 7, 2007 Thank effigy. That was exactly what I was looking for. Link to comment https://forums.phpfreaks.com/topic/41688-solved-new-problem/#findComment-202050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.