Answer the question
In order to leave comments, you need to log in
Why is the array not unloaded in the database completely?
I work with someone else's self-written hosting, where I have access only via FTP.
The site was written by myself and uploaded by myself.
But when adding an array, not the entire array is entered into the database.
That is, there is a gallery of pictures on the page, I set 32 pictures through the admin panel, and 18 will be entered.
What could be the problem?
Adding code is general:
<?php
session_start();
if ($_SESSION['auth_admin'] == "yes_auth")
{
define('supercleaning', true);
if (isset($_GET["logout"]))
{
unset($_SESSION['auth_admin']);
header("Location: index.php");
}}
include("include/db_connect.php");
include("functions/functions.php");
if ($_POST["submit_add"])
{
$error = array();
// Проверка полей
if (!$_POST["form_title"])
{
$error[] = "Укажите заголовок";
}
if (!$_POST["brands"])
{
$error[] = "Укажите бренд";
}
if (count($error))
{
$_SESSION['message'] = "<p id='form-error'>".implode('<br />',$error)."</p>";
}else
{
$brands = $_POST['brands'];
$zagalovok = $_POST['form_title'];
$link = mysqli_connect($db_host, $db_user, $db_password, $db_database)
or die("Ошибка " . mysqli_error($link));
$query ="INSERT INTO proizvoditel ( proizvoditel, brand ) VALUES
( '$zagalovok', '$brands')";
$result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
//Если запрос пройдет успешно то в переменную result вернется true
if($result == 'true')
{echo "Ваши данные успешно добавлены";}
else {echo "Ваши данные не добавлены";}
$_SESSION['message'] = "<p id='form-success'>Данные успешно добавлены!</p>";
$id = mysqli_insert_id($link);
if (empty($_POST["upload_image"]))
{
include("actions/upload-plitka.php");
unset($_POST["upload_image"]);
}
if (empty($_POST["galleryimg"]))
{
include("actions/upload-gallery.php");
unset($_POST["galleryimg"]);
}
if (empty($_POST["opisanie"]))
{
include("actions/upload-gallery.php");
unset($_POST["opisanie"]);
}
} }
?>
<?php
$link = mysqli_connect($db_host, $db_user, $db_password, $db_database)
or die("Ошибка " . mysqli_error($link));
if($_FILES['galleryimg']['name'][0]){
for($i = 0; $i < count($_FILES['galleryimg']['name']); $i++){
$error_gallery = "";
if($_FILES['galleryimg']['name'][$i]){
$galleryimgType = $_FILES['galleryimg']['type'][$i]; // тип файла
$types = array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"); // массив допустимых расширений
// расширение картинки
$imgext = strtolower(preg_replace("#.+\.([a-z]+)$#i", "$1", $_FILES['galleryimg']['name'][$i]));
//папка для загрузки
$uploaddir = '../uploads_plitka/';
//новое сгенерированное имя файла
$newfilename = $_POST["brands"].'-'.$id.rand(10,30000).'.'.$imgext;
//путь к файлу (папка.файл)
$uploadfile = $uploaddir.$newfilename;
$opisanie = $_POST['opisanie'][$i];
if(!in_array($galleryimgType, $types)){
$error_gallery = "<p id='form-error'>Допустимые расширения - .gif, .jpg, .png</p>";
$_SESSION['answer'] = $error_gallery;
continue;
}
if (empty($error_gallery))
{
if(@move_uploaded_file($_FILES['galleryimg']['tmp_name'][$i], $uploadfile)){
mysqli_query($link,"INSERT INTO uploads_images(products_id,image,opisanie)
VALUES(
'".$id."',
'".$newfilename."',
'".$opisanie."'
)");
}else{
$_SESSION['answer'] = "Ошибка загрузки файла.";
}
}
}
}
}
?>
<form enctype="multipart/form-data" method="post">
<div class="form-group">
<label>Название производителя</label> <br/>
<input type="text" name="form_title" />
</div>
<div class="form-group">
<label>БРЕНД (КАТЕГОРИЯ)</label><br/>
<input type="text" name="brands" />
</div>
<div class="form-group">
<div id="baseimg-upload">
<label class="stylelabel" >Главная картинка</label>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000"/>
<input type="file" name="upload_image" />
</div> </div>
<div class="form-group">
<label class="stylelabel" >Основная плитка</label>
<div id="objects" >
<div id="addimage1" class="addimage">
<input type="text" size="50" name="opisanie[]" />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"/>
<input type="file" name="galleryimg[]" /><br>
</div>
</div> </div>
<p id="add-input" >Добавить</p>
<p align="right" ><input type="submit" id="submit_form" name="submit_add" value="Добавить товар"/></p>
</form>
Answer the question
In order to leave comments, you need to log in
values must be normalized, use mysqli_escape_string or similar function
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question