gpt4 book ai didi

php - 在动态表中显示信息和附件名称

转载 作者:行者123 更新时间:2023-11-29 11:21:08 25 4
gpt4 key购买 nike

    <div>

大家好,我的 table 允许我输入汽车信息并附上他们的卡的副本。然后,我可以通过单击“添加数据”按钮输入另一行来添加另一行。这里的问题是,当我提交信息时,只显示第一辆车的信息及其上传的卡,但第二辆车只显示卡名称。

<!---/ html table /--->
<table class="" id="tab_logic1">
<thead>
<tr class="success">
<th colspan="6">SECTION 4: LIST OF VEHICLES <small><i>(Please list down vehicles registered in company names. Attach vehicle registration card)</i></small></th>
</tr>

<tr>
<th>#</th>
<th class="text-center">Registration Number</th>
<th class="text-center" >Make</th>
<th class="text-center" >Type</th>
<th class="text-center" >Capacity</th>
<th class="text-center" >Attach</th>

</tr>
</thead>
<tbody>
<tr id='addrw0'>
<td>1</td>
<td><input type="text" class="form-control" name='registrationNumber[]' ></td>
<td><input type="text" class="form-control" name='vehicleMake[]' ></td>
<td><input type="text" class="form-control" name='vehicleType[]' ></td>
<td><input type="text" class="form-control" name='VehicleCapacity[]' ></td>
<td class="text-center"><input type="file" name="files[]" class="btn btn-sm btn-primary"></td>
</tr>
<tr id='addrw1'></tr>
</tbody>
<tfoot>
<tr>
<th colspan='6'>
<a id="add_new_row" data-placement="right" class="btn btn-info pull-left" data-toggle="tooltip" title="Add another vehicle">Add Data</a>
<a id="delete_new_row" data-placement="left" class="pull-right btn btn-info" data-toggle="tooltip" title="Remove vehicle">Delete Data</a>

</th>
</tr>

</tfoot>

</table>
<!--jquery for adding rows-->

$(document).ready(function(){
var i=1;
$("#add_new_row").click(function(){
$('#addrw'+i).html("<td>"+ (i+1) +"</td><td><input type='text' name='registrationNumber[]"+i+
"' class='form-control' required></td><td><input type='text' name='vehicleMake[]"+i+
"' class='form-control' required></td><td><input type='text' name='vehicleType[]"+i+
"' class='form-control' required></td><td><input type='text' name='VehicleCapacity[]"+i+
"' class='form-control' required></td><td><input type='file' name='files[]"+i+
"' class='btn btn-sm btn-primary' required></td>");

$('#tab_logic1').append('<tr id="addrw'+(i+1)+'"></tr>');
i++;
});
$("#delete_new_row").click(function(){
if(i>1){
$("#addrw"+(i-1)).html('');
i--;
}
});

});

<!---displaying each row information with its attachment-->
<?php
$errors = array();

$messages = array();
if (isset($_POST["submitbtn"])) {


$registrationNumber = count($_POST["registrationNumber"]);

$vehicleMake = $_POST["vehicleMake"];

$vehicleType = $_POST["vehicleType"];

$VehicleCapacity = $_POST["VehicleCapacity"];

// $file_name = $_FILES['files']['names'];



for($x=0;$x<$registrationNumber;$x++) {

$file_name = $_FILES['files']['name'][$x];
$file_size = $_FILES['files']['size'][$x];
$file_type = $_FILES['files']['type'][$x];
$file_tmp = $_FILES['files']['tmp_name'][$x];

$messages[] = "Your car is ".$_POST["vehicleMake"][$x]." and card is ".$file_name;



}
/*displaying message*/

if (isset($messages)) {
foreach ($messages as $message) {
echo '<div class="alert alert-success text-center" style="font-size: 14px;font-weight:bold;" role="alert">'.$message.'</div>';
}
}
?>

最佳答案

它对我有用

$("#add_new_row").click(function(){
$('#addrw'+i).html("<td>"+ (i+1) +"</td><td><input type='text' name='registrationNumber[]' class='form-control' required></td><td><input type='text' name='vehicleMake[]' class='form-control' required></td><td><input type='text' name='vehicleType[]' class='form-control' required></td><td><input type='text' name='VehicleCapacity[]' class='form-control' required></td><td><input type='file' name='files[]' class='btn btn-sm btn-primary' required></td>");

$('#tab_logic1').append('<tr id="addrw'+(i+1)+'"></tr>');
i++;
});**strong text**

关于php - 在动态表中显示信息和附件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com