Jump to content

Archived

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

john_6767

multiple insert using checkboxes

Recommended Posts

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/files.aspx?categoryid=15&filecategoryid=10). Anyone know of any tutorials or code to do this in php?

Share this post


Link to post
Share on other sites
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:
[code]
<?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";
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites
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?

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.