使用 php pdo 将多个数据保存到数据库

Save multiple data to database with php pdo

我使用 php pdo 将多个数据保存到数据库中。但我认为这里有问题。它不会将该信息保存在数据库中。你能帮帮我吗?

$connect=$db->prepare("INSERT INTO slide3yazi SET title=:title, description=:description, product_id=:product_id");
            $connect->execute(['title'=>$_POST['slider3_title'], 'description'=>$_POST['slider3_description'], 'product_id'=>$uruns['urun_id']]);

            for($i; $i <= $_POST['slider3_number']; $i++){
                echo $description3 = $_POST["slider3_icerik_$i"];

                $rand1 = rand(10,10000000);
                $upload_dir = "../assets/img/urun_icon";
                $tmp_name = $_FILES["slider3_resim_$i"]["tmp_name"];
                $name = $_FILES["slider3_resim_$i"]['name'];
                $logo = substr($upload_dir, 3)."/".$rand1.$name;
                @move_uploaded_file($tmp_name, "$upload_dir/$rand1$name");
                $connect=$db->prepare("INSERT INTO slider3 SET description=:description, photo=:photo, product_id=:product_id");
                $connect->execute(['description'=>$description3, 'photo'=>$logo, 'product_id'=>$uruns['urun_id']]);
            }

您的代码非常混乱。这里我给你插入代码。

$data = ['description' => $description,
        'photo' => $photo,
        'product_id' => $product_id,];
$sql = "INSERT INTO users (description, photo, product_id) VALUES (:description, :photo, :product_id)";
$stmt= $pdo->prepare($sql);
$stmt->execute($data);

您可以获得关于此的更多信息url