how to insert multiple checkbox values in multiple rows mysql database using php pdo?
Please give multiple insert option
Here is my script:
$create = sizeof(isset($_POST['create']) ? $_POST['create'] : array());
$edit = sizeof(isset($_POST['edit']) ? $_POST['edit'] : array());
$delete = sizeof(isset($_POST['delete']) ? $_POST['delete'] : array());
$view = sizeof(isset($_POST['view']) ? $_POST['view'] : array());
$status = sizeof(isset($_POST['status']) ? $_POST['status'] : array());
$modulename = sizeof(isset($_POST['modulename']) ? $_POST['modulename'] : array());`
for($i=0; $i< ($create && $edit && $delete && $view && $status); $i++)
{
$insertmodule = $DB->prepare("INSERT INTO `np_role_rights`(`rr_rolecode`, `rr_modulecode`, `rr_create`, `rr_edit`, `rr_delete`, `rr_view`, `rr_status`, `pharmacy_id`, `superadmin_id`, `created_by`) VALUES (:rr_rolecode, :rr_modulecode, :rr_create, :rr_edit, :rr_delete, :rr_view, :rr_status, :pharmacy_id, :superadmin_id, :created_by)");
$insertmodule->execute(array(
':rr_rolecode'=>$rolecode1,
':rr_modulecode'=>$modulename,
':rr_create'=>$create,
':rr_edit'=>$edit,
':rr_delete'=>$delete,
':rr_view'=>$view,
':rr_status'=>$status,
':pharmacy_id'=>$person_rowid,
':superadmin_id'=>$u_userid,
':created_by'=>$u_userid
));
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Pharmacy Succesfully Created')
window.location.href='pharmacy-management.php';
</SCRIPT>");
}
<?php
$roleper = $DB->prepare("SELECT * from np_module ORDER BY mod_modulegrouporder");
$roleper->execute();
$numrows = $roleper->rowCount();
if($numrows > 0)
{
for($i=0; $result = $roleper->fetch(); $i++)
{
$modulegroup = $result['mod_modulegroupname'];
$modulename = $result['mod_modulename'];
echo "
<table border='0'>
<tr><td colspan='2'><strong>$modulegroup</strong></td></tr>
<tr><td> </td><td><input type='text' name='modulename' value='$modulename' hidden=''/>
$modulename
<tr>
<td colspan='2'>
<table style='width:100%; height:100px;' border='0'>
<tr>
<td>
<input type='checkbox' name='create[]' value='yes'>
</td>
<td>
Create
</td>
<td>
<input type='checkbox' name='edit[]' value='yes'>
</td>
<td>
Edit
</td>
</tr>
<tr>
<td>
<input type='checkbox' name='delete[]' value='yes'>
</td>
<td>
Delete
</td>
<td>
<input type='checkbox' name='view[]' value='yes'>
</td>
<td>
View
</td>
</tr>
<tr>
<td>
<input type='checkbox' name='status[]' value='yes'>
</td>
<td>
Status
</td>
</tr>
</table>
</td>
</tr>
<br><br></td></tr>
</table>
";
}
}
else
{
echo "Module Not Found";
}
?>