Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<div id="project_aminities" class="project_aminities">
         <label>Aminities:</label>
            <input type="checkbox" value="Gym" name="aminities[]">Gym
            <input type="checkbox" value="Indoor Games" name="aminities[]">Indoor Games
            <input type="checkbox" value="Children Play Area" name="aminities[]">Children Play Area
            <input type="checkbox" value="Swimming Pool" name="aminities[]">Swimming Pool
            <input type="checkbox" value="Multi Function Hall" name="aminities[]">Multi Function Hall
            <input type="checkbox" value="Jogging Track" name="aminities[]">Jogging Track<br>
    </div>

C#
<script>

    jQuery(document).ready(function()
    {
        jQuery('#submit').click(function()
        {
             var aminities = $('input[type=checkbox]:checked').map(function(_, el) {
        return $(el).val();
    }).get();


        var jsonString = JSON.stringify(aminities);


            jQuery.ajax(
            {
                type:"POST",
                url:"sample_project_details.php",
                data: {data : jsonString},
                cache: false,
                success:function(data)
                {
                    alert('OK');
                }
            });
        });
    });

</script>




PHP
<?php

mysql_connect("localhost","root","myfourwalls");

mysql_select_db("test");


$aminitiesData = json_decode(stripslashes($_POST['data']));


?>

What should I do store the selected checkbox values to MYSQL DB(inside the column called aminities)?Number of selected values differ each time I Submit my Form.
Posted
Comments
Prava-MFS 13-Nov-14 4:40am    
For me, it is giving all the right data, the one I am selecting. No issues at all for me. Please check once again and print the data like print_r($aminitiesData); exit; in your PHP file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900