Jump to content


This topic is now archived and is closed to further replies.


Array from form to DB insert

Recommended Posts

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')";

At this time, the insert is not working.  Also, when I tried to see if the data was even being collected via:

$user_id_array = $_POST['user_ID'];
echo '<pre>';
echo '</pre>';

the result was an empty 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.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.