gpt4 book ai didi

php - 使用循环插入数据时出现数据库错误

转载 作者:行者123 更新时间:2023-11-29 07:18:15 24 4
gpt4 key购买 nike

我想使用动态 php 变量在数据库中插入数据,当我检查数据库中的脚本时,我只有一条记录:(

$low_0 = 0;
$low_1 = 1;
$low_2 = 2;
$nr = 9;

for ($i = 0; $i < $nr; $i++) {
$sql = 'INSERT INTO prognoza_curenta (ora, prognoza, min, max, reg_date)
VALUES (' . "${'low_' . $i}, " . "11," . "22," . "33," . "'$timp')";
echo "$sql" . "<br>";
}

if (mysqli_query($db, $sql)) {
echo 'Data send' . "<br>";
} else {
echo 'Error send.' . mysqli_error($sql) . "<br>";
}

最佳答案

将循环更改为:

$sql = 'INSERT INTO prognoza_curenta (ora, prognoza, min, max, reg_date)  VALUES';
for ($i = 0; $i < $nr; $i++) {
$sql .= ' (' . "${'low_' . $i}, " . "11," . "22," . "33," . "'$timp')";
}

关于php - 使用循环插入数据时出现数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37100043/

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