lurking Posted October 26, 2006 Share Posted October 26, 2006 I have a form that lists a bunch of names with a checkbox next to each one. If the checkbox is checked, the data is inserted into my DB. Whereas previously, the checkbox value was just a variable (user_ID), now I need it to be an array to pass two variables (user_ID + db_designation):[code]<input name="user_ID[]" type="checkbox" id="user_ID[]"value="<?php echo urlencode(serialize(array($row_rsPhysicianDetails['user_ID'], $row_rsPhysicianDetails['db_designation']))); ?>" />[/code]I grab the array data via:[code]<?php $user_id_array = $_POST['user_ID']; ?>[/code]and then have been attempting to insert into my database with a foreach() and nested if() loop.[code]<?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "attendance")) { foreach($user_id_array as $value) { list($user, $designation) = unserialize($value); if ($designation == "p") { $query = "INSERT INTO course_complete (user_ID, course_ID, course_date, credit_hours, course_session)" . "VALUES($user, '$c_ID', '$c_date', '$credit_hours', '$course_session')"; @mysql_query($query); } }?>[/code]At this time, the insert is not working. Also, when I tried to see if the data was even being collected via:[code]<?php$user_id_array = $_POST['user_ID'];echo '<pre>'; print_r($_POST);echo '</pre>';?>[/code]the result was an empty array:Array{}I would appreciate any ideas for making sure the variable $user_id_array is populating appropriately, and then making the insert work with the foreach, if, serialize and list syntax. Thank you. Link to comment https://forums.phpfreaks.com/topic/25217-array-from-form-to-db-insert/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.