0

Hi Master,

please help me, i could not insert my multiple checkbox selected value into my table. please see and help me.
its insert only one value like first one. here is code:

**HTML code: **

<td width="75%">
<input type="checkbox" name="whats_include[]"  value="Breakfast" > Breakfast / 
<input type="checkbox" name="whats_include[]"   value="Lunch" > Lunch / 
<input type="checkbox" name="whats_include[]" value="Dinner" > Dinner /
<input type="checkbox" name="whats_include[]"  value="Drink" > Drink /
<input type="checkbox" name="whats_include[]"  value="Transport" > Transport 
</td>

PHP Value Insert Code

if($_POST)
    {
        $per = $_POST['whats_include'];    
        foreach($per as $p) {
          $inclues=  $p.',';
          $data['whats_include'] = $inclues;
         dumpVar($data);
        }
        insert(tbl_new_package, $data)   //insert query (table, $data)//
    }

Output:

Array
(
    [user_id] => 1
    [trip_name] => bangla tour
    [tour_type] => none
    [day] => 
    [nights] => 
    [service_level] => ---None---
    [min_person] => 0
    [max_person] => 1
    [whats_include] => Breakfast,
)

here is details code.please help me .

Regards

2
Contributors
4
Replies
21
Views
3 Years
Discussion Span
Last Post by diafol
0

You're overwriting the $includes on every iteration...

$includes = array();
foreach($per as $p) {
      $inclues[] =  $p;

    }
$data['whats_include'] = implode(", ", $includes);
dumpVar($data);    
0

Hi, Thanks for reply.but its nothing pass any single data. :(
**i used it like **

$includes = array();
$per = $_POST['whats_include'];    
foreach($per as $p) {
      $inclues[] =  $p;
    }
$data['whats_include'] = implode(", ", $includes);
dumpVar($data); 

Output :

Array
(
    [user_id] => 1
    [trip_name] => bangla tour
    [tour_type] => none
    [day] => 
    [nights] => 
    [service_level] => ---None---
    [min_person] => 3
    [max_person] => 5
    [whats_include] => 
)

now what will i do? please

0

Many thanks for help me its working now and you always help me as a Master

please see i used like this:

$myvalue = $_POST['whats_include'];
        foreach ($myvalue as $avalue)
            {
            $include[] = $avalue;
            }
        $p = implode(", ", $include);   
        $data['whats_include'] = $p;

Thanks again. :)

0

I included the loop as I thought you wanted to do something with the individual values, but if not, why not do this?

$data['whats_include'] = implode(", ", $_POST['whats_include']);

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.