I want to create a mysql insert statement in a for-loop. I'm looking for to insert multiple records at a time.
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);
i got a error about
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
the label tabel:
Field Type null
item_id int(11) NO
label varchar(50) NO
i cannot find the mistake, please help me to find it..