0

I refer to this page: Post array of multiple checkbox values

<input type="checkbox" class="box"  value="blue" title="A" />
<input type="checkbox" class="box"  value="red" title="B" />
<input type="checkbox" class="box"  value="white" title="C"/>

$('#include').click(function(){

    var val = $('.box:checked').map(function(i,n) {
        return $(n).val();
    }).get(); //get converts it to an array         

    var title = $('.box:checked').map(function(i,n) {
        return $(n).attr('title');
    }).get(); //get converts it to an array     

    $.post(url, {'val[]': val,'title[]':title}, function(response) {
        alert('scuess');
    });
        return false;
})
---------------------------------------------
<?php
   foreach($_GET['val'] as $numA)
   {
        foreach($_GET['title'] as $numB)
       {
            $str="insert into user_photos (val,title) values ('$numA','$numB')";
            mysql_query($str,$link); 
       }
   }
?>

Please tell me how to do that...

1
  • what's the problem then? Commented Aug 3, 2010 at 6:56

2 Answers 2

0

do it this way...

jQuery

$('#include').click(function(){

    var data = $('.box:checked').map(function(i,n) {
        return {'val':$(n).val(), 'title': $(n).attr('title')};
    }).get(); //get converts it to an array         

    $.post(url, {'data': data}, function(response) {
        alert('scuess');
    });
        return false;
});

PHP

<?php
   foreach($_GET['data'] as $data)
   {
       $str="insert into user_photos (val,title) values ('$data[val]','$data[title]')";
       mysql_query($str,$link); 
   }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not a pro at PHP but try print_r($_GET['data']); to see what values are being sent to the server..
0
<input type="checkbox" class="box[A]" value="blue" />
<input type="checkbox" class="box[B]" value="red" />
<input type="checkbox" class="box[C]" value="white" />
<?
// load multi-dimensional array
$values = $_POST['box'];
foreach($values as $title) {
    foreach($title as $val) {
        // insert $title/$val into mySQL
    }
}
?>

Comments

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.