I have a web page with many rows which has two input.Maybe 10 rows, maybe 100 rows, it depends on how many times button addP is clicked. These input values should be inserted into IDC table with idc_addDVC.php.
I want to use while loop for many input data.But unfortunately these data can't be inserted into IDC table with my idc_addDVC.php.
ClOUDT and IDC tables show nothing after submit.Here is my JS code:
<script>
var aDWI=1;
function addPf()
{
newrow = '<tr><td style="width:25%" colspan="2"><input style="width:98%" name="enName'+aDWI+'"></td><td style="width:85%" colspan="2"><input style="width:98%" name="enID'+aDWI+'"></td></tr>';
$(newrow).insertAfter($('#staTable tr:eq('+aDWI+')'));
aDWI = aDWI + 1;
$('#engID').attr("value",aDWI);
}
</script>
Here is my html code:
<div>
<form action="idc_addDVC.php?act=add&table=IDC" method="POST">
<table>
<tr>
<input type="button" id="addP" onclick="addPf()" value="AP">
</tr>
<tr>
<input type="text" name="enName">
<input type="text" name="enID">
</tr>
<tr>
newrow is added here
</tr>
<tr>
<td>
<input type="submit" value="submitBtn">
<input type="hidden" id="engID" value="1" name="engRow">
</td>
</tr>
</table>
</form>
</div>
Here is fail idc_addDVC.php code:
<?php
if($_GET["act"]=="add")
{
$conn=new PDO('mysql:host=localhost;port=3306;dbname=xxx' , 'root' , 'xxx');
$query="begin declare i int;
set i=1;
insert into ClOUDT (customer) values ('JOHN');
while i < ".$_POST['engRow']."
do
insert into IDC (name,id,cloudeid) values('".$_POST['enName'+i]."','".$_POST['enID'+i]."',LAST_INSERT_ID());
set i=i+1;
end while;
commit;";
$stmt=$conn->query($query);
echo "success";
......
}
else
{
echo "fail";
......
}
}
?>
Here is successful idc_addDVC.php code:
<?php
if($_GET["act"]=="add")
{
$conn=new PDO('mysql:host=localhost;port=3306;dbname=xxx','root','xxx');
$query="begin ;
insert into ClOUDT (customer) values ('JOHN');
insert into IDC (name,id,cloudeid) values('".$_POST['enName']."','".$_POST['enID']."',LAST_INSERT_ID());
commit;";
$stmt=$conn->query($query);
echo "success";
......
}
else
{
echo "fail";
......
}
}
?>
I suppose 'enName'+i in $query of idc_addDVC.php is wrong. But i have no idea how to get the dynamic input values.It is complex , who can help me ?