0

I have for example in mysql table: fruit_store id fruit price

and I have form like:

<a href="#" id="add_input">Add</a> 
<a href="#" id="remove_input">Remove</a>  
    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
        <table id="workTbl">
            <tr>
                <td>Fruit</td>
                <td>Price</td>
            </tr>
        </table>
        <p><input name="submit" type="submit" id="submit_tbl" /></p>
       </form>

and have jquery code:

$(function(){
    $("#add_input").click(function(){
        $("#workTbl").append("<tr><td><input name='fruit_input' type='text' /></td><td><input name='price_input' type='text' /></td></tr>");
    });
    $("#remove_input").click(function(){ 
         $('#workTbl input:last').remove();
         $('#workTbl input:last').remove();           
    })
});

I want to ask how to insert multiple inputs into mysql table fruit_store with one submit button or multiple forms i don't know help me please!

1
  • How do you insert value now? What do you have done? Commented May 26, 2011 at 15:59

2 Answers 2

1

use [] in the input name as in here

   <input name='fruit_input[]' .... />

then in php upon receiving post data, loop through

  if (is_array($_POST['fruit_input'])){
   foreach ($_POST['fruit_input'] as $key=>$value){
        $price=$_POST['fruit_price'][$key];
        ...
Sign up to request clarification or add additional context in comments.

Comments

0

you need to put some php code to see what fields have are present in the post array use

<?php 

 if( ! empty( $_POST ) )
{

   $sql = "insert into table  ......values ...";

   mysql_query($sql);

}
?>

to check how many values are present in the post array use

print_r($_POST)

i hope you will understand from here onward.

Comments

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.