0

I have a form which consist of a multi-D array. It has both checkbox and text. So i would like to use both values to enter them in database. I could not figure out how to use them. Any help would be much appreciated. Here is my code ;

 $clothes = array(
              "For_Man"=>array("Suit", "Tie"),
              "For_Woman"=>array("Skirt","Bra")
                );

   echo '<form action="" method="POST">';

 foreach ($clothes as $cloth => $task) {

   echo "<strong>{$cloth}</strong> <br />";

 foreach ($task as $type){

   echo "<input type=\"checkbox\" name=\"box[]\" value=\"{$type}\" />\r
   {$type} <input type=\"textbox\" name=\"note[]\" size=\"2\" /><hr />\r";

  }
 }

    echo "<input type=\"Submit\" name=\"submit\" value=\"Submit\" />\r
    </form>";

 if(isset($_POST['box'])){
 if(isset($_POST['note'])){
    $note = $_POST['note'];
  }
 $box = $_POST['box'];
 }

So user can select the item and enter the amount they want so i can use it to enter database like

new_order = mysql_query("INSERT INTO orders(cloth_name, amount,... ) VALUES     ('$box', '$note', ...........");

1 Answer 1

0

I really don't understand you, do you want to save each product of your array in the database? if it is the case you can put it in another table you know,

=products=

Id_Product

name

=Orders

Id_Order

...

=Products_Orders

Id_PO

Id_Product

Id_Order

amount

note

instead of putting the information in a unique table.

2
  • my question is that i want to get the data from the form if it is checked and the value entered. basically, if user select skirt and enter the amount of 10. i want to use these values to store in database.
    – romansmac
    Commented Aug 18, 2014 at 22:35
  • well, if you have your array of checked items use their key to identify the amount next to it, I say you have: name="box[]" name="note[]" So, you access to each element: $boxes = $_POST["box"] ; $notes = $_POST["note"] ; for($i=0; $i < count($boxes); $i++){ //supposing both have content this print that content. echo $boxes[$i]; echo $notes[$i]; } only you have to pass the data to your query.
    – Lord_Gama
    Commented Aug 19, 2014 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.