2 回答
TA贡献1799条经验 获得超9个赞
您在数据集之间缺少逗号,并且也不需要将它们全部括起来。您已经在使用rtrim()删除最后一个逗号,但实际上并没有在数据集的末尾添加逗号。
foreach ($diurno as $userId) {
//add a comma at the end
//note you can write variables directly into a string that is wrapped with double quotes
$data .= "('$id', '$grdid', '$userId', '$contacto', '$pos_laboral', '$contacto2', '$idd'),";
}
//this gets rid of the very last comma in the string
$data = rtrim($data, ',');
//remove parenthesis around `$data`
$sql = "insert into cursosprogramas (departamento, codigocurso, diurno, contacto, pos_laboral, contacto2, proc_por) values {$data};";
echo $sql;
注意:Little Bobby表示这段代码可能面临 SQL 注入攻击的风险,具体取决于其中变量的$data
创建方式。
TA贡献1830条经验 获得超3个赞
您需要在值元组之间使用逗号。尝试在第二行末尾加一个逗号,如下所示:
foreach ($diurno as $userId) {
$data .= "(".$id.",".$grdid.",".$userId.",".$contacto.",".$pos_laboral.",".$contacto2.",".$idd."),";
}
$data = rtrim($data, ',');
$sql = "insert into cursosprogramas (departamento, codigocurso, diurno, contacto, pos_laboral, contacto2, proc_por) values (".$data.");";
echo $sql;
- 2 回答
- 0 关注
- 138 浏览
添加回答
举报