Jump to content


Photo

Array from form to DB insert


  • Please log in to reply
No replies to this topic

#1 lurking

lurking
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 October 2006 - 06:10 PM

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):

<input name="user_ID[]" type="checkbox" id="user_ID[]"
value="<?php echo urlencode(serialize(array($row_rsPhysicianDetails['user_ID'],
 $row_rsPhysicianDetails['db_designation']))); ?>" />

I grab the array data via:
<?php $user_id_array = $_POST['user_ID']; ?>

and then have been attempting to insert into my database with a foreach() and nested if() loop.

<?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);
  }
  }
?>

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

<?php
$user_id_array = $_POST['user_ID'];
echo '<pre>'; 
print_r($_POST);
echo '</pre>';
?>

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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users