[SOLVED]Posting form data in many rows of database?

Here is what my form looks like:

<form name="form1" method="post" action="testing.php">
          <?php if (isset($_GET['Component_ID'])) {
  $Component_ID = (get_magic_quotes_gpc()) ? $_GET['Component_ID'] : addslashes($_GET['Component_ID']);
} ?>
     <input type="hidden" name="Component_ID" value="<?php if (isset($Component_ID)) { echo $Component_ID; }?>" />
      <?php // 4. Use database retured data

while ($row = mysql_fetch_array($db_result1)) {
	echo "<input type="checkbox" name="Product_ID" " . "value="" . $row["Product_ID"] . "" />" . " " . $row["Product_Name"] . " <br />" ;

      <input type="submit" value="Submit" />
    </p><?php if (isset($Component_ID)) { echo $Component_ID; }?>

When I check all of the boxes and I submit this form the data it returns on the testing page is:


How do I take that post/get string. Turn it in an array or something and insert it into the database like this:
Component_ID=1 > Product_ID=1
Component_ID=1 > Product_ID=2
Component_ID=1 > Product_ID=3
Component_ID=1 > Product_ID=4

I am trying to build a relational table between my products and the components…

I just do not get how I can do this.

is this solvers as well?

echo “<input type=“checkbox” name=“Product_ID[]” " . “value=”” . $row[“Product_ID”] . “” />" . " " . $row[“Product_Name”] . "
" ;

this will give u:

now $_POST[‘Product_ID’] is an array already:
[php]mysql_query(‘DELETE FROM Products WHERE Component_ID=’.intval($_POST[‘Component_ID’])); /* neded to remove the not checked values */

foreach($_POST[‘Product_ID’] as $prod_id)
mysql_query(‘INSERT INTO Products SET Product_ID=’.intval($prod_id).’, Component_ID=’.intval($_POST[‘Component_ID’]));

Your way is so much better!!!


I came up with some crappy code that does the same thing but its like 50 lines!

I will change my code to reflect yours…

Thanks again.

This post is Solved… how do I make it solved?

u may edit ur first message in this topic. and change the title adding [SOLVED].

Sponsor our Newsletter | Privacy Policy | Terms of Service