Welcome Guest, Not a member yet? Register   Sign In
How do i insert multiple selected checkboxes into the database
#1

[eluser]itz4mesays[/eluser]
I am trying to insert multiples values from selected checkboxes into the database and i can only insert one out of it. Tried your using insert_batch() but not getting it. I think i get the array properly. Can anyone please help me out? Thanks for your swift response and time to stop by to read this post.

My View
if(isset($select) && count($select)){
echo '<table border="1" cellspacing="0" cellpadding="3">';
//$data=array('onsubmit'=>'return confirmdelete()');
echo form_open('student/add_courses');
//echo"&lt;form method='post' name='form' id='form' acti confirmdelete();'&gt;";
echo '<tr valign="top">';
echo "<th width='50' align='center'>&lt;input id='delete' type='submit' name='delete' value='x'/&gt;&lt;/th>";
echo '<th>Course Code</th>';
echo '<th>Course Title</th>';
echo '<th>Course Unit</th>';
echo '<th>Course Status</th>';
echo '<th>Level</th>';
echo '<th>Semester</th>';

echo '</tr>';

foreach ($select as $key => $row) {

echo '<tr valign="top">';
echo '<td align="center">&lt;input type="checkbox" name="checkbox[]" id="checkbox[]" value='.$row['id'].'&gt;&lt;/td>';
echo '<td align="center">'.$row['course_code'].'</td>';
echo '<td align="center">'.$row['course_title'].'</td>';
echo '<td align="center">'.$row['course_unit'].'</td>';
echo '<td align="center">'.$row['course_status'].'</td>';
echo '<td align="center">'.$row['level'].'</td>';
echo '<td align="center">'.$row['semester'].'</td>';

echo '</tr>';

//echo $row['id'];
}
echo '</table>';
echo"&lt;/form&gt;";


#2

[eluser]PravinS[/eluser]
when you will post the form, you will get "checkbox[]" values in array, so according to its number of element you can insert records in database

first check the "checkbox[]" values by print_r('checkbox')
#3

[eluser]itz4mesays[/eluser]
I got Array ( [0] => 110 [1] => 109 [2] => 108 [3] => 107 [4] => 106 ) when i used the print_r() but i want to be able to post the other fields alongside with the id to another table. Two tables are involved:
i. courses - This contains the courses that are added
ii. studcourses - contains courses that are added from the courses table.

Please i need your help. Thanks




Theme © iAndrew 2016 - Forum software by © MyBB