Jump to content

[SOLVED] new problem


brodywx

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.