gpt4 book ai didi

php在for循环中插入数据到sql

转载 作者:行者123 更新时间:2023-11-29 01:13:02 25 4
gpt4 key购买 nike

<分区>

我想在 for 循环中创建一个 mysql 插入语句。 我想一次插入多条记录。

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$label =htmlspecialchars( $_POST["label"]);
$splitLabel = explode(" ", $label);//split the label to a array
}
//.....insert another data, getting the $last_id here

$sql = $result = "";
for ($i =0; $i< count($splitLabel); $i++){
if ($i < count($splitLabel)){
$sql .= "INSERT INTO label (item_id, label)
VALUES ('".$last_id."', '".$splitLabel[$i]."');";
}else{
$sql .= "INSERT INTO label (item_id, label)
VALUES ('".$last_id."', '".$splitLabel[$i]."')";
}
}
$result = mysqli_query($conn, $sql);

我有一个关于

的错误
 check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO label (item_id, label)
VALUES ('13', 'tin');INSERT INTO label (' at line 2

标签标签:

Field      Type           null
item_id int(11) NO
label varchar(50) NO

我找不到错误,请帮我找到它..

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com