orion
orion

Reputation: 1

Make multiple inputs in mysql table at once with one submit button

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!

Upvotes: 0

Views: 1608

Answers (2)

Khurram Ijaz
Khurram Ijaz

Reputation: 1864

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.

Upvotes: 0

Dreaded semicolon
Dreaded semicolon

Reputation: 2294

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];
        ...

Upvotes: 1

Related Questions