PHP只读取动态创建的输入数组的第一个值
PHP only read the first value of input array dynamic created
很抱歉英语不好,我还在学习。。。
我在HTML中有一个只有的表
<tr id="linha_1">
<td><input type="text" name="nome_cor[]" value="" /></td>
<td><input type="text" name="cod_cor[]" value="" /></td>
<td><input type="file" name="img_cor[]" /></td>
<td><input type="button" value="Remover" id="remove" onclick="$.removeLinha(this);" /></td>
</tr>
我还有一个JS脚本,它向这个表添加新行,这个脚本复制了第一行,这样用户就可以添加更多的颜色。。。
$(document).ready(function()
{
var row_limit = 0;
$('#add').click(function()
{
var linha_total = $('tbody#repetir tr').length;
if (row_limit == 0 || row_limit > linha_total)
{
var linha = $('tbody#repetir tr').html();
var linha_total = $('tbody#repetir tr').length;
var linha_id = $('tbody#repetir tr').attr('id');
$('tbody#repetir').append('<tr id="linha_' + (linha_total + 1) + '">' + linha + '</tr>');
}
else
{
alert("Desculpe, mas você só pode adicionar até " + limite_linhas + " linhas!");
}
});
使用malsup表单插件通过post:发送数据
$("#send").click(function(event) {
event.preventDefault();
$("#form-tapete").ajaxForm({
// validation and progress bar (*not important to the question i think*)
},
url: 'dados-tapete.php',
resetForm: false
}).submit();
我正试图用以下代码在PHP中阅读这篇文章:
for ($i=0; $i < sizeof($cod_cor); $i++)
{
$path_cor = "catalogo/tapete/cor/";
$path_cor = $path_cor.basename($_FILES["img_cor"]["name"][$i]);
if (!move_uploaded_file($_FILES["img_cor"]["tmp_name"][$i], $path_cor))
die("Ocorreu um erro ao enviar a imagem, tente novamente!");
$cor_img_name = "catalogo/tapete/cor/".$_FILES["img_cor"]["name"][$i];
$cadastra_cores = $con->sql_query("INSERT INTO tape_cores VALUES ('$nome_tapete','$cod_cor[$i]','$nome_cor[$i]','$path_cor')");
}
PHP脚本可以读取值并将其发送到数据库,但只有第一个值。。。动态添加的行不会出现在$_POST数组中。。。
我搜索了一下,在这里找到了一些问题,但没有解决方案。。。
很抱歉英语又不好了,如果你听不懂我的话,我可以试着用其他的话来解释。。。感谢
我会将JQuery与以下内容一起使用:
$.post( "test.php", $( "#testform" ).serialize() );
对于Malsup JQuery,请使用formSerialize();
var queryString = $('#myFormId').formSerialize();
$.post('myscript.php', queryString);
相关文章:
- $q.all当输入数组中的一项不是promise时,Typescript检查器失败
- 你能提交一个带有文本输入数组的表单吗
- 使用 jQuery 和 Ajax 发送输入数组
- $.when.apply 根据输入数组的长度返回具有不同结构的结果
- PHP只读取动态创建的输入数组的第一个值
- 使用jquery设置输入数组值
- 使用 javascript 验证输入数组
- 角度 UI 预测文本:如何输入未包含在输入数组中的数据
- 将动态输入索引到其他动态输入数组
- 循环遍历输入数组以设置值,“无法设置未定义的属性值”
- 在输入数组元素时在 html 页面中显示数组元素
- Javascript 隐藏输入数组
- 编码然后在 base64 中解码不会输出我的输入数组缓冲区
- 将隐藏的输入数组传递给 jQuery load()
- 将输入数组中的特定输入值发送到 JavaScript
- 在输入数组的 split() 和子字符串 () 之后的文本区域中显示
- Jquery 添加未传递给 php 的输入数组字段
- Javascript函数显示用户输入数组
- 从输入数组中获取sum's元素
- 如何在文本输入数组中插入字符串