Hello! I want to create a new file for each file in the database, help the second day I suffer

$error_list = implode(',', $error_list); $success_list = implode(',', $success_list); $success_list_small = implode(',', $success_list_small); $id = $_GET['id']; require_once( $_SERVER['DOCUMENT_ROOT'] . '/bd.php'); $sqlimage .= "INSERT INTO images_big(id, catalog, filename, catalog_small, filename_small) VALUES foreach($success_list as $success_lists){ $sqlimage .=("'.$id.'" ,"'.$uploads_dir.'" ,"'.$success_lists.'" ,"'.$uploads_dir_smale.'" ,"'.$success_list_small.'") }"; $sqlimage.=implode(',',$array); $stmtimg = $pdo->query($sqlimage); $stmtimg->execute(); 

  • No one was embarrassed that he had a cycle in the request? - Joker2620

1 answer 1

Generating a SQL query in this way is an extremely bad practice. More correctly, first prepare the request and execute each INSERT separately

 $stmt = $pdo->prepare("INSERT INTO images_big(id, catalog, filename, catalog_small, filename_small) VALUES (?,?,?,?,?)"); $id = $_GET['id']; //НичСго, Ρ‡Ρ‚ΠΎ Ρƒ Π½ΠΈΡ… Ρƒ всСх id Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΉ? $catalog = '/какая/Ρ‚ΠΎ/дирСктория'; $catalog_small = 'дирСктория'; $success_list = [массив ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ]; $success_list_small = [Π΄Ρ€ΡƒΠ³ΠΎΠΉ массив, Π½ΠΎ элСмСнтов ΡΡ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΆΠ΅, сколько Π² $success_list ]; $stmt->bindParam(1,$id,PDO::PARAM_INT); $stmt->bindParam(2,$catalog,PDO::PARAM_STR); $stmt->bindParam(3,$filename,PDO::PARAM_STR); $stmt->bindParam(4,$catalog_small,PDO::PARAM_STR); $stmt->bindParam(5,$filename_small,PDO::PARAM_STR); for($i=0;$i<count($success_list);$i++){ $filename=$success_list[$i]; $filename_small=$success_list_small[$i]; $stmt->execute(); } 
  • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash ♦