samedi 5 décembre 2015

how to input 2d array checkbox into database using php

hye, I need help in making 2d array checkbox data into database. From now, i manage to output the data but then I don't know how to get the data into database. I'm using php.

//in form

$query = mysql_query("Select userName from user where userType = '2'  ORDER     BY userName ASC");

while ($row = mysql_fetch_array($query)) {          

echo'<input type="checkbox" name="userArea1[][]" value="'.$row['userName'].'">'.$row['userName'].'</br>';                                   

}


//output
print_r ($_POST['userArea1']);

Array ( [0] => Array ( [0] => Mary ) [1] => Array ( [0] => John ) [2] => Array ( [0] => Liana ) [3] => Array ( [0] => Hana ) [4] => Array ( [0] => Yuki ) [5] => Array ( [0] => Lily ) ) 


//Try to input into database
if (isset($_POST['submit']))
{
 $chkbox = $_POST['userArea1'];
 $i = 0;

 for($j=0; $j<$sesArea; $j++)
 { 
    While($i<sizeof($chkbox))
 {
    $query = "INSERT INTO reportdetail (reportTeam) VALUES ('".$chkbox[$j][$i]."')";

    mysql_query($query) or die(mysql_error());

    $i++;
    }
    }
    echo "Checkbox value is successfully submitted.";
    }

//error

Notice: Undefined offset: 1 in C:\xampp\htdocs\consulting\adminCreateReport2Validate.php on line 37

Notice: Undefined offset: 2 in C:\xampp\htdocs\consulting\adminCreateReport2Validate.php on line 37

Notice: Undefined offset: 3 in C:\xampp\htdocs\consulting\adminCreateReport2Validate.php on line 37

Notice: Undefined offset: 4 in C:\xampp\htdocs\consulting\adminCreateReport2Validate.php on line 37

Notice: Undefined offset: 5 in C:\xampp\htdocs\consulting\adminCreateReport2Validate.php on line 37 Checkbox value is successfully submitted.

Aucun commentaire:

Enregistrer un commentaire