1

I saved multiple data to the database with php pdo. but i think there is a problem here. It does not save that information in the database. Can you help me?

$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']]);
            }
2
  • You can not use set in insert query Commented Aug 18, 2021 at 13:11
  • What can I use? Commented Aug 18, 2021 at 13:15

1 Answer 1

1

Your code is very confusing. Here I gave you insert code.

$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);

YOu can get more information on this url.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.