所有我需要帮助,我最近遇到了麻烦。 我有动态行字段,因此我的用户可以动态添加字段。
这是 php 文件
<table id="myTable" class="basic-table table order-list">
<thead>
<tr>
<th data-priority="1">Job Title</th>
<th data-priority="1">Company</th>
<th data-priority="1">Job desc</th>
<th data-priority="1">Job Start</th>
<th data-priority="1">Job End</th>
<th data-priority="1">Action</th>
</tr>
</thead>
<tbody>
<?php
$cekdata="SELECT * from jobhis where id_tr='$id' ORDER BY id_jobhis ASC";
$ada=mysql_query($cekdata) or die(mysql_error());
if(mysql_num_rows($ada)==0) {
echo "<td align='center' colspan='6' class='blue-tbg'>No Job Experience</td></tr>";
}
else{
$query = "SELECT * from jobhis where id_tr='$id' ORDER BY id_jobhis ASC";
$sql = mysql_query($query);
while($data = mysql_fetch_array($sql)) {
echo"<tr>
<td>
<input id='rows_$data[id_jobhis]' name='baris[]' value='$data[id_jobhis]' type='hidden'>
<input type='hidden' name='idjobhis $data[id_jobhis]' parsley-trigger='change' required class='form-control' id='idjobhis $data[id_jobhis]' value='$data[id_jobhis]'>
<input type='text' name='rnmjob $data[id_jobhis]' parsley-trigger='change' required class='with-border' id='rnmjob $data[nm_jobhis]' value='$data[nm_jobhis]'>
<input type='hidden' name='idtr $data[id_jobhis]' parsley-trigger='change' required class='form-control' id='idtr $data[id_tr]' value='$data[id_tr]'>
</td>
<td>
<input type='text' name='rcpjob $data[id_jobhis]' parsley-trigger='change' required class='with-border' id='rcpjob $data[id_jobhis]' value='$data[cp_jobhis]'>
</td>
<td>
<textarea name='rjobdesc $data[id_jobhis]' cols='40' rows='3' id='rjobdesc $data[id_jobhis]' maxlength='300' class='with-border' required>$data[desc_jobhis]</textarea>
</td>
<td>
<input type='text' name='rstartjob $data[id_jobhis]' parsley-trigger='change' required class='with-border' id='rstartjob $data[id_jobhis]' data-mask='99/99/9999' value='$data[start_jobhis]'>
</td>
<td>
<input type='text' name='rendjob $data[id_jobhis]' parsley-trigger='change' required class='fwith-border' id='rendjob $data[id_jobhis]' data-mask='99/99/9999' value='$data[end_jobhis]'>
</td>
<td>
<a href='#small-dialog-$data[id_jobhis]' class='apply-now-button popup-with-zoom-anim'>Remove</a>
</td>
</tr>
<div id='small-dialog-$data[id_jobhis]' class='zoom-anim-dialog mfp-hide dialog-with-tabs'>
<div class='sign-in-form'>
<div class='popup-tabs-container'>
<div class='popup-tab-content' id='tab'>
<div class='welcome-text'>
<h3>Confirmation</h3>
</div>
<p>Are you sure to remove job experience as <strong>$data[nm_jobhis] at $data[cp_jobhis]</strong> ?</p>
<a href='director.php?act=del-sertif&id_trsertif=$data[id_tr]&id_job=$data[id_jobhis]' class='button ripple-effect'>Remove</a>
</div>
</div>
</div>
</div>";
}
}
?>
</tbody>
</table>
<input type="button" class="btn btn-lg btn-block " id="addrow" value="Add Row" />
这是 js脚本,用于添加动态行
<script>
$(document).ready(function(){ var counter = 1;
$("#addrow").on("click", function () {
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="hidden" id="baris_' + counter + '" name="baris[]" value="'+ counter +'" ><input type="text" class="with-border" name="xnmjob' + counter + '" required/></td>';
cols += '<td><input type="text" class="with-border" name="xnmcp' + counter + '" required/></td>';
cols += '<td><textarea name="xdescjob' + counter + '" cols="40" rows="3" maxlength="300" class="with-border" required></textarea> </td>';
cols += '<td><input type="text" class="with-border" name="xstartjob' + counter + '" data-mask="99/99/9999" required/></td>';
cols += '<td><input type="text" class="with-border" name="xendjob' + counter + '" data-mask="99/99/9999" required/></td>';
cols += '<td><input type="button" class="ibtnDel btn btn-md btn-danger " value="Delete"></td>';
newRow.append(cols);
$("table.order-list").append(newRow);
counter++;
});
$("table.order-list").on("click", ".ibtnDel", function (event) {
$(this).closest("tr").remove();
counter += 1
});
});
这是数据库脚本
if(isset($_POST['rows']) && is_array($_POST['rows']) && count($_POST['rows'])>0)
{
foreach ($_POST['rows'] as $count ){
$xnmjob = $_POST['xnmjob_'.$count];
$xnmcp = $_POST['xnmcp_'.$count];
$xdescjob = $_POST['xdescjob_'.$count];
$xstartjob = $_POST['xstartjob_'.$count];
$xendjob = $_POST['xendjob_'.$count];
$queryadd = "INSERT INTO jobhis VALUES ('','$id_tr','$nama''$xnmjob','$xcpjob','$xstartjob','$xendjob','$xdescjob')";
mysql_query($queryadd) or die(mysql_error());
}
}
但是当我提交表单时,php没有索引动态生成的行。.请帮助..谢谢