I am getting last inserted row in save page when adding dynamically inserting each row.
any body help me i want to get all records in save page.

my add-remove-row.php is

<htmnl>
<head>
</head>
<body>
    <form action="save.php"  method="post" name="assigndate"  enctype="multipart/form-data" >

<table rules="all" style="background:#fff;">
<tr>
<td style="font-size:14px;" >Name</td>
<td style="font-size:14px;">Email</td>
<td style="font-size:14px;">Mobile</td>
<td><span style="font:normal 12px agency, arial; color:blue; text-decoration:underline; cursor:pointer;" onClick="addMoreRows(this.form);">
Add More
</span>
</td>
</tr>
<tr id="rowId">
<td><input name="name" type="text"   id="name" size="17%"/></td>
<td><input name="email" type="text" id="email" /></td>
<td><input name="mobile" type="text" id="mobile"   /></td>
</tr>

</table>
<tr><td>
<div id="addedRows"></div>
</td>
</tr>

<input type="submit" name="submit" id="submit" value="submit"/>


</form>



<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var rowCount = 1;
function addMoreRows(frm) {
rowCount ++;
var recRow = '<p id="rowCount'+rowCount+'"><tr><td><input name="name" id="name" type="text" size="17%"  maxlength="120" /></td><td><input name="email" id="email" type="text"  maxlength="120" style="margin: 4px 5px 0 5px;"/></td><td><input name="mobile" id="mobile" type="text" maxlength="120" style="margin: 4px 10px 0 0px;"/></td></tr> <a href="javascript:void(0);" onclick="removeRow('+rowCount+');">Delete</a></p>';
jQuery('#addedRows').append(recRow);
}

function removeRow(removeNum) {
jQuery('#rowCount'+removeNum).remove();
}
</script>

</body>
</html>

and my save page is save.php



<?php

$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$mobile=$_REQUEST['mobile'];

echo $name;
echo $email;
echo $mobile;

?>

The reason you code can just get the last added items is probably because the tructure you design will only add rows with the input elements with same name and id which are 'name','email' and 'mobile' means the form only will post one name, one email and one mobile to your save.php
If I am in the case, I will probably add the rowCount to the input name such as <input name="name'+rowCount+'" id="name'+rowCount+'" type="text" size="17%" maxlength="120" /> and so as email and mobile field.
And I will create a hidden input to store the rowCount to send to save.php. In save.php I will read the rowCount and use a for loop to loop the data posted.

Very thanks problem is solved but i am not getting while clicking button

my modified code is

<html>
<head>
<title>jQuery add / remove textbox example</title>

      <script src="jquery.min.js"></script>

<style type="text/css">
    div{
        padding:8px;
    }
</style>

</head>

<body>

<h1>jQuery add / remove textbox example</h1>

<script type="text/javascript">

$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" name="mytext[]"/><input type="text" name="email[]"/><input type="text" name="mobile[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box







        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })


$("#getValue").click(function() {

 var mytext1=$("#mytext").val();
    alert(x);

    });


});
</script>
</head><body>
 <form name="myform" action="save1.php" method="post" enctype="multipart/form-data" >
<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="text" name="mytext[]" id="mytext">
    <input type="text" name="email[]" id="email">
    <input type="text" name="mobile[]" id="mobile"></div>
</div>
<input type="button" value="getValue" id="getValue">
 <input type="submit" name="submit" />
 </form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.