Jump to content


Photo

multiple insert using checkboxes


  • Please log in to reply
2 replies to this topic

#1 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 03 October 2006 - 02:30 AM

i'm trying to make an insert page that adds in a client and also adds into the client_areas table the areas that the client is interested in.. (these areas are displayed as checkboxes from the area table..) so i have to insert the client and then insert multple times into the client_areas joining table. I have use a script in asp before and it works exactly right but now i am using php i cannot work out how to do it. (script is in asp and called 'Insert/Update Multiple Tables', i found it here http://charon.co.uk/...lecategoryid=10). Anyone know of any tutorials or code to do this in php?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 03 October 2006 - 03:30 AM

one of the easiest ways i've found to do this is simply to name all the associated checkboxes as an array and to loop through them all on the processing page:
<?php
if (isset($_POST['submit'])) {
  // check to see at least one of your "myCheck" boxes was submitted
  if (isset($_POST['myCheck']) && count($_POST['myCheck']) > 0) {
    foreach ($_POST['myCheck'] as $val) {
      // now, here is where you would insert your value into your database
    }
  }
}

echo "<form name=\"test\" action=\"\" method=\"post\">\n";
for ($i = 1; $i <= 10; $i++) echo "<input type=\"checkbox\" name=\"myCheck[]\" value=\"$i\" /> $i<br />\n";
echo "<input type=\"input\" name=\"submit\" value=\"Submit\" />\n";
echo "</form>\n";
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 03 October 2006 - 11:13 PM

this does help a bit with concepts but i don't know enough php to get a working version.. do you have a simple working example page i could look at?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users