Hello, I have a script with the addition of images to the server and the path to them in the database, so I can’t do so that the names of all the images fall into comma-separated lines in one field. I only get one last image in the database, and all images are loaded on the server. here is the code

<?php session_start(); if (empty($_SESSION[login])) { exit ("Страница не найдена!"); } mysql_connect("", "", ""); mysql_select_db(""); if (isset($_FILES)) { //пролистываем весь массив изображений по одному $_FILES['file']['name'] as $k=>$v foreach ($_FILES['uploadfile']['name'] as $k => $v) { $err = array(); { // Каталог, в который мы будем принимать файл: $uploaddir = 'images/'; $uploadfile = $uploaddir . basename($_FILES['uploadfile']['name'][$k]); // Копируем файл из каталога для временного хранения файлов: if (!copy($_FILES['uploadfile']['tmp_name'][$k], $uploadfile)) { $error[] = "<div class='dannye'><h3>Ошибка! Не удалось загрузить файл на сервер!</div></h3>"; } if (count($error) == 0) $uploaddire = $uploaddir; $uploadfilee = $_FILES['uploadfile']['name'][$k]; //$uploadfiles = explode(',', $uploadfilee); //$getMime = $_FILES['uploadfile']['name'][$k]; { $sqlimage = mysql_query("UPDATE `users` SET catalog='" . $uploaddire . "', filename='" . $uploadfilee . "' WHERE login='" . $_GET['login'] . "'"); //выводим результат\ if (isset($sqlimage)) { echo "<div class='dannye'><p>даные вставлены </p> " . $uploadfilee . "</div>"; } else { print "<div class='dannye'><b>При добавленнии изображения произошли следующие ошибки:</b><br>"; foreach ($error AS $errors) { print $errors . "<br>"; } print "</div>"; } } } } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Загрузка изображения на сервер</title> <script src="javascript.js"></script> <link rel="stylesheet" type="text/css" href="style.css"/> <link rel="stylesheet" type="text/css" href="header.css"> <style type="text/css"> .dannye { position: relative; top: 370px; font-size: 16px; } </style> </head> <body> <header> <p>Загрузка изображения на сервер</p> </header> <div class="content"> <? mysql_connect("", "", ""); mysql_select_db(""); print_r($_GET['login']); ?></p> <form action='' method='post' enctype='multipart/form-data'> <input type='file' name='uploadfile[]' multiple='true'/> <input type='submit' value='Загрузить'></form> </div> </body> </html> 
  • You are updating each time one and the same line in the database: "' WHERE login='" . $_GET['login'] . "'" "' WHERE login='" . $_GET['login'] . "'" "' WHERE login='" . $_GET['login'] . "'" - this construction finds the line where the user login corresponds to the login from $_GET['login'] and update the fields there for those values ​​that lie in $uploaddire and $uploadfilee - Alexandr
  • did not help bury foreach to sql - Koly

1 answer 1

Because you are grinding the value in the database

 $sql "UPDATE `users` ". "SET catalog='" . $uploaddire . "', filename='" . $uploadfilee . "' ". "WHERE login='" . $_GET['login'] . "'"; $sqlimage = mysql_query($sql);