我有这样的功能:
function insert2(){
$i=0;
$query = "insert into ".$this->table_name." values(?,?,?,'','',?)";
# i've try below code, but just insert 1 row to mysql
# $query = "insert into ".$this->table_name." values(?,?,?,'','',CURDATE())";
foreach ($this->ik as $key => $value){
$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $this->ia);
$stmt->bindParam(2, $value);
$stmt->bindParam(3, $this->nn[$key]);
# $stmt->bindParam(6, CURDATE());
$stmt->execute();
$i++;
}
return $i;
}
如何修复多个插入只插入1行?
有什么想法吗?
修改
我的专栏看起来像
|------|------|------|--?--|--?--|------|
| ia | ik | nn | ? | ? | date |
|------|------|------|-----|-----|------|
每种形式的输入应该向mysql插入1行,如下所示:
输入表单的输出示例是
Array ( [ia] => 6 [ik] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) [nn] => Array ( [0] => 80 [1] => 79 [2] => 79 [3] => 80 ) )
如果您想对我的问题进行投票,请注释原因
答案 0 :(得分:1)
只需将值放入SQL ...
即可$query = "insert into ".$this->table_name." values(?,?,?,'','',curdate())";