4

I am codeigniter php developer.so , i need to send the database multiple checkbox values.first of all i created table with prefer, holiday, facility and accomadation fields.

controller

if($_POST)
{
    $prefer= $this->input->post('prefer');
    $data['prefer'] = array(
            'prefer' => implode(",", $prefer),
        ); 

    $holiday= $this->input->post('holiday');
    $data = array(
            'holiday' => implode(",", $holiday),      
        );
    $facility= $this->input->post('facility');
    $data = array(
            'facility' => implode(",", $facility),      
        );
    $accommodation= $this->input->post('accommodation');
    $data = array(
            'accommodation' => implode(",", $accommodation),      
        );

    $this->customize->save_customize_tour_detail($data);
}

view

Wild & adventurous
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="prefer[]" value="romantic"  />Romantic & sensuous
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="prefer[]" value="healthy"  />Healthy & rejuvenating
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="prefer[]" value="fun"  />Fun & exciting
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="prefer[]" value="peaceful"  />Thought provoking & peaceful
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="prefer[]" value="shopping"  />Shopping
                        </label>
                    </div></div>

                    <div style="float:left">
                    <label for=""><font color="#00CC66">What whould you like to see in a holiday?</font></label>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="holiday[]" value="beach"  />Beaches
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="holiday[]" value="wild"  />Wild life
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="holiday[]" value="fauna"  />Fauna & flora
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="holiday[]" value="archeological"  />Archeological sites
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="holiday[]" value="mountains"  />Mountains & waterfalls
                        </label>
                    </div></div></div>
                    <br><br><br><br><br><br><br><br><br><br>

                    <div>
                  <div style="float:left; margin-right:30px;">

                    <label for=""><font color="#00CC66">What is the most important facility you need?</font></label>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="facility[]" value="comfortable"  />Comfortable accommodation
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="facility[]" value="transportation"  />Transportation
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="facility[]" value="guide"  />Guide assistance
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="facility[]" value="excellent"  />Excellent food
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="facility[]" value="communication"  />Communication
                        </label>
                    </div></div>

                  <div style="float:left">
                    <label for=""><font color="#00CC66">What kind of accommodation pleases you?</font></label>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="accommodation[]" value="standard_duest_house"  />Standard Guest Houses
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="accommodation[]" value="three_star"  />3 Star Hotels
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="accommodation[]" value="five_star"  />5 Star Hotels
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="accommodation[]" value="two_star"  />2 Star Hotels
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>

                            <input type="checkbox" name="accommodation[]" value="four_star"  />4 Star Hotels
                        </label>
                    </div>

model

function save_customize_tour_detail($data) {
    $this->db->insert('ba_customize_tours',$data);
}

problem is when i click the send button only accomadation value goes to table.others(prefer,holoday,facility) values not going to table.

2

1 Answer 1

3

Try this code:

if($_POST)
{
    $prefer= $this->input->post('prefer');
    $data['prefer'] =implode(",", $prefer);           

    $holiday= $this->input->post('holiday');
    $data['holiday'] = implode(",", $holiday);  

    $facility= $this->input->post('facility');
    $data['facility'] = implode(",", $facility);

    $accommodation= $this->input->post('accommodation');
    $data['accommodation'] = implode(",", $accommodation);


    $this->customize->save_customize_tour_detail($data);
}
Sign up to request clarification or add additional context in comments.

1 Comment

it is work perfect..thank you so much your promp support

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.