如何在while循环语句中插入许多有价值的数据。mysql-PHP
事务在我的PHP页面中使用,因为hpcid是IDC表的外键 我有一百行人的信息(姓名、id、电话)将被插入IDC表中,所以我想使用while循环 在没有while循环的情况下,我测试了人员信息的三行数据,它可以正常工作。但是当添加while循环时,它失败了 在这里,代码正常工作:如何在while循环语句中插入许多有价值的数据。mysql-PHP,php,mysql,Php,Mysql,事务在我的PHP页面中使用,因为hpcid是IDC表的外键 我有一百行人的信息(姓名、id、电话)将被插入IDC表中,所以我想使用while循环 在没有while循环的情况下,我测试了人员信息的三行数据,它可以正常工作。但是当添加while循环时,它失败了 在这里,代码正常工作: $query="begin ; insert into HPC (name, begindata, enddate) VALUES('".$_POST['customerName']."','".$_POST[
$query="begin ;
insert into HPC (name, begindata, enddate) VALUES('".$_POST['customerName']."','".$_POST['firstDay']."','".$_POST['lastDay']."');
insert into IDC (name,id,phone,hpcid) VALUES('".$_POST['enName3']."','".$_POST['enID3']."','".$_POST['enPhone3']."',LAST_INSERT_ID());
insert into IDC (name,id,phone,hpcid) VALUES('".$_POST['enName4']."','".$_POST['enID4']."','".$_POST['enPhone4']."',LAST_INSERT_ID());
insert into IDC (name,id,phone,hpcid) VALUES('".$_POST['enName5']."','".$_POST['enID5']."','".$_POST['enPhone5']."',LAST_INSERT_ID());
commit;";
$stmt=$conn->query($query);
此处,添加的while循环工作失败代码:
$query="begin ;
declare i int;
set i = 5;
insert into ".$_GET['table']." (name, begindate,enddate) VALUES('".$_POST['customerName']."','".$_POST['firstDay']."','".$_POST['lastDay']."');
insert into IDC (name,id,phone,hpcid) VALUES('".$_POST['enName3']."','".$_POST['enID3']."','".$_POST['enPhone3']."',LAST_INSERT_ID());
insert into IDC (name,id,phone,hpcid) VALUES('".$_POST['enName4']."','".$_POST['enID4']."','".$_POST['enPhone4']."',LAST_INSERT_ID());
while i<106
do
insert into IDC (name,id,phone,hpcid) VALUES('".$_POST["enName'+i+'"]."','".$_POST["enID'+i+'"]."','".$_POST["enPhone'+i+'"]."',LAST_INSERT_ID());
set i = i +1;
end while;
commit;";
$stmt=$conn->query($query);
谁能帮我
name id phone
john1 1 123
john2 2 234
john3 3 345
......
john100 100 3453