I added the data to mysql but its not true. There are a few lines manually duplicating data. Add and commands my update it still works.I don't understand why the data added to the unsatisfactory. Who can help me not? thanks
this is code html:
<form id="myform" method="post">
<div>
<div>
<div>
<!--dongggggggggggggggggg 2-->
<?php
$select = mysql_query("Select * from Salary where code='C'");
$resultmax = mysql_query("SELECT MAX(stt) AS max_page FROM Salary where code='C'");
$rowmax = mysql_fetch_array($resultmax);
while ($resultRow = mysql_fetch_array($select)) {
?>
<div class="row">
<div class="col-lg-12">
<input type="text" name="stt[]"
value="<?php echo $resultRow['stt'] ?>"
style="float:left; width:20px; border:none"
readonly/>
<input type="hidden" name="d[]" value="C"
style="float:left; width:20px; border:none"/>
<input id="dd" name="a[]" class="col-lg-35 a"
value="<?php echo $resultRow['col_a'] ?>"
type="text">
<input name="b[]" class="col-lg-35 a nhay"
value="<?php echo $resultRow['col_b'] ?>"
onblur="luu()" type="text">
<input name="c[]" class="col-lg-35 a"
value="<?php echo $resultRow['col_c'] ?>"
onblur="luu()" type="text">
<input name="check_save" class="col-lg-1" type="checkbox"
value="" onclick="return false;">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-lg-12">
<input type="hidden" name="d[]" value="C"
style="float:left; width:20px; border:none"/>
<input name="stt[]"
value="<?php echo $rowmax["max_page"] + 1 ?>"
style="float:left; width:20px;border:none" readonly/>
<input id="dd" name="a[]" class="col-lg-35 a" value=""
type="text">
<input name="b[]" class="col-lg-35 a"
onblur="luu()" value="" type="text">
<input name="c[]" class="col-lg-35 a"
onblur="luu()" value="" type="text">
<input id="save" name="check_save" class="col-lg-1 ab"
type="checkbox" value="" onclick="return false;">
</div>
</div>
<div class="row" id="c">
<div class="col-lg-12">
<input type="hidden" name="d[]" value="C"
style="float:left; width:20px; border:none"/>
<input name="stt[]" id="stt"
value="<?php echo $rowmax["max_page"] + 2 ?>"
style="float:left; width:20px;border:none" readonly/>
<input id="dd" name="a[]" class="col-lg-35 a" value=""
type="text" >
<input name="b[]" class="col-lg-35 a nhay"
onblur="luu()" value="" type="text">
<input name="c[]" class="col-lg-35 a"
onblur="luu()" value="" type="text">
<input id="save" name="check_save" class="col-lg-1 ab"
type="checkbox" value="" onclick="return false;">
</div>
</div>
<!--dongggggggggggggggggg 1-->
<br>
</div>
</div>
</div>
<div>
<di>
<div>
<!--dongggggggggggggggggg 1-->
<?php
$select = mysql_query("Select * from Salary where code='P'");
$resultmax = mysql_query("SELECT MAX(stt) AS max_page FROM Salary where code='P'");
$rowmax = mysql_fetch_array($resultmax);
while ($resultRow = mysql_fetch_array($select)) {
?>
<!--dongggggggggggggggggg 1-->
<!--dongggggggggggggggggg 2-->
<div class="row">
<div class="col-lg-12">
<input type="text" name="stt[]"
value="<?php echo $resultRow['stt'] ?>"
style="float:left; width:20px; border:none"
readonly/>
<input type="hidden" name="d[]" value="P"
style="float:left; width:20px; border:none"/>
<input id="dd" name="a[]" class="col-lg-35 a"
value="<?php echo $resultRow['col_a'] ?>"
type="text">
<input name="b[]" class="col-lg-35 a nhay"
value="<?php echo $resultRow['col_b'] ?>"
onblur="luu()" type="text">
<input name="c[]" class="col-lg-35 a"
value="<?php echo $resultRow['col_c'] ?>"
onblur="luu()" type="text">
<input name="check_save" class="col-lg-1" type="checkbox"
value="" onclick="return false;">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-lg-12">
<input type="hidden" name="d[]" value="P"
style="float:left; width:20px; border:none"/>
<input name="stt[]"
value="<?php echo $rowmax["max_page"] + 1 ?>"
style="float:left; width:20px;border:none" readonly/>
<input name="a[]" class="col-lg-35 a" value="" type="text">
<input name="b[]" class="col-lg-35 a" value="" onblur="luu()" type="text">
<input name="c[]" class="col-lg-35 a" value=""
onblur="luu()" type="text">
<input id="save" name="check_save" class="col-lg-1 ab" type="checkbox" value="" onclick="return false;">
</div>
</div>
<!--dongggggggggggggggggg 1-->
<!--dongggggggggggggggggg 2-->
<div class="row" id="d">
<div class="col-lg-12">
<input type="hidden" name="d[]" value="P" style="float:left; width:20px; border:none"/>
<input name="stt[]" value="<?php echo $rowmax["max_page"] + 2 ?>" style="float:left; width:20px;border:none" readonly/>
<input id="dd" name="a[]" class="col-lg-35 a" value="" type="text">
<input name="b[]" class="col-lg-35 a nhay" value="" onblur="luu()" type="text">
<input name="c[]" class="col-lg-35 a" value="" onblur="luu()" type="text">
<input id="save" name="check_save" class="col-lg-1 ab" type="checkbox" value="" onclick="return false;">
</div>
</div>
<!--dongggggggggggggggggg 1-->
<br>
</div>
</di>
</div>
</form>
this is javascript :
<script type="text/javascript" language="javascript">
function luu() {
$.ajax({
type: 'POST',
url: 'insert.php',
data: $('#myform').serialize(),
dataType: 'JSON',
success: function (data) {
check();
}
});
}
$(document).ready(function () {
var currentBoxNumber = 0;
$(document).on('keyup', '.a', function (e) {
if (e.keyCode == 13) {
textboxes = $("input.a");
currentBoxNumber = textboxes.index(this);
if (textboxes[currentBoxNumber + 1] != null) {
nextBox = textboxes[currentBoxNumber + 1];
if (nextBox.id == "dd") {
luu();
}
nextBox.focus();
return false;
}
}
});
var i = document.getElementById("stt").value;
$(document).on('keyup', '.nhay', function (e) {
if (e.keyCode == 13) {
$('.a').removeClass('nhay');
var y = parseInt(i) + parseInt(1);
$('#c').append('<div><input type="hidden" name="d[]" value="C" style="float:left; width:20px; border:none"/><input name="stt[]" value="' + y + '" style="float:left; width:20px;border:none" readonly/><input id="dd" name="a[]" class="col-lg-35 a" value="" type="text"><input name="b[]" onblur="luu()" class="col-lg-35 a nhay" value="" type="text"><input name="c[]" onblur="luu()" class="col-lg-35 a" value="" type="text" ><input id="save" name="check_save" class="col-lg-1 ab" type="checkbox" value="" onclick="return false;"></div>');
$('#d').append('<div><input type="hidden" name="d[]" value="P" style="float:left; width:20px; border:none"/><input name="stt[]" value="' + y + '" style="float:left; width:20px;border:none" readonly/><input id="dd" name="a[]" class="col-lg-35 a" value="" type="text"><input name="b[]" onblur="luu()" class="col-lg-35 a nhay" value="" type="text"><input name="c[]" onblur="luu()" class="col-lg-35 a" value="" type="text" ><input name="check_save" class="col-lg-1 ab" type="checkbox" value="" onclick="return false;"></div>');
i++;
}
});
});
<script>
function check() {
var myForm = document.forms.myform;
var myControls = $(myForm).find('input[name="a[]"]').filter(function () {
if (!$.trim(this.value)) {
$(this).siblings('.ab').prop('checked', false)
} else {
$(this).siblings('.ab').prop('checked', true)
}
});
}
this is insert.php :
$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];
$sott=$_POST['stt'];
$d=$_POST['d'];
$index=0;
foreach($a as $s){
$check="Select ID from Salary where stt='".$sott[$index]."' and code='".$d[$index]."'";
$result1 = mysql_query($check);
$myid = mysql_num_rows($result1);
if ($myid==null)
{
$sql = "INSERT INTO Salary(code,col_a,col_b,col_c,stt) VALUES('".$d[$index]."','$s','".$b[$index]."','".$c[$index]."','".$sott[$index]."')";
$result = mysql_query($sql);
}
else
{
$sql="Update Salary set col_a='$s',col_b='".$b[$index]."',col_c='".$c[$index]."' where stt='".$sott[$index]."' and code='".$d[$index]."'";
$result = mysql_query($sql);
}
$index++;
}
if ($result) { echo "1";}