Jump to content

Dynamic form values not send to the database


hasiwarna

Recommended Posts

I have this bellow code its a jquery to add form elements dynamically. my question is when Im submiting the form to the database it only send first set of elements value only, rest are not sending to the database, plz help me on this..

here is my codes. jquery-

<script type="text/Javascript">
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedSection').length;
var newNum = new Number(num + 1);

var newSection = $('#pq_entry_' + num).clone().attr('id', 'pq_entry_' + newNum);

newSection.children(':first').children(':first').attr('id', 'contNo_' + newNum).attr('name', 'contNo_' + newNum);
newSection.children(':nth-child(2)').children(':first').attr('id', 'contNo2_' + newNum).attr('name', 'contNo2_' + newNum);
newSection.children(':nth-child(3)').children(':first').attr('id', 'contNo3_' + newNum).attr('name', 'contNo3_' + newNum);
newSection.children(':nth-child(4)').children(':first').attr('id', 'contNo4_' + newNum).attr('name', 'contNo4_' + newNum);
newSection.children(':nth-child(5)').children(':first').attr('id', 'contNo5_' + newNum).attr('name', 'contNo5_' + newNum);
newSection.children(':nth-child(6)').children(':first').attr('id', 'contNo6_' + newNum).attr('name', 'contNo6_' + newNum);

newSection.insertAfter('#pq_entry_' + num).last();

$('#btnDel').prop('disabled','');

if (newNum == 5)
$('#btnAdd').prop('disabled','disabled');
});

$('#btnDel').click(function() {
var num = $('.clonedSection').length; // how many "duplicatable" input fields we currently have
$('#pq_entry_' + num).remove(); // remove the last element

// enable the "add" button
$('#btnAdd').prop('disabled','');

// if only one element remains, disable the "remove" button
if (num-1 == 1)
$('#btnDel').prop('disabled','disabled');
});

$('#btnDel').prop('disabled','disabled');
});

//$('#blinfo').on('submit', function (e) {
//prevent the default submithandling
// e.preventDefault();
//send the data of 'this' (the matched form) to yourURL
// $.post('bladd.php', $(this).serialize());
//});

</script>

Here is the HTML (both codes are in the same file)

<ul id="pq_entry_1" class="clonedSection"> 
<li><input type="text" name="contNo_1" id="contNo_1" size="45" value=""/></li>
<li>SIZE<input type="text" name="contNo2_1" id="contNo2_1" size="15" value=""/></li>
<li>MODE<input type="text" name="contNo3_1" id="contNo3_1" size="15" value=""/></li>
<li>PICES<input type="text" name="contNo4_1" id="contNo4_1" size="15" value=""/></li>
<li>WEIGHT<input type="text" name="contNo5_1" id="contNo5_1" size="15" value=""/></li>
<li>VOLUME<input type="text" name="contNo6_1" id="contNo6_1" size="15" value=""/></li>
</ul>

<input type='button' id='btnAdd' size="15" value='add another row' /><input type='button' id='btnDel' value='delete row' />

and here is my sql query

<?php
$con=mysqli_connect("localhost","root","1234","shipping");
// Check connection
if (mysqli_connect_errno())
{
mysqli_connect_error();
}

$sql="INSERT INTO infobl (contNo_1, contNo2_1, contNo3_1, contNo4_1, contNo5_1, contNo6_1, contNo_2, contNo2_2, contNo3_2, contNo4_2, contNo5_2, contNo6_2, datetime)
VALUES
('$_POST[contNo_1]','$_POST[contNo2_1]','$_POST[contNo3_1]','$_POST[contNo4_1]','$_POST[contNo5_1]','$_POST[contNo6_1]','$_POST[contNo_2]','$_POST[contNo2_2]','$_POST[contNo3_2]','$_POST[contNo4_2]','$_POST[contNo5_2]','$_POST[contNo6_2]',NOW())";

if (!mysqli_query($con,$sql))
{
die('<font color="#FF0000"><h2>Error: ---PLEASE CHECK YOUR NUMBER AGAIN....<br />Press Back on the browser.... </h2></font>' . mysqli_error($con)) ;
}
else header('location: /bldrft/edits/view.php');


mysqli_close($con);

?>

I can't figure it out what was the wrong, all are fine to me, plzz help guys. thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.