Implemented a simple admin site. It consists of two forms for creating a collection of photos, in the first form all the necessary lines are entered as name, location, etc., and the number of photos in the collection is also entered. After it is sent, all the necessary columns are generated in the collection row in the database, including the required number of rows of photos, which was specified in the form, names are generated for them. This stage works absolutely fine, everything you need in the database is created and created correctly. Then, after updating the database, the page on it is updated by the submission of the previous form, the form for downloading photos opens, it generates the necessary amount of input for photos, depending on how many were specified, after selecting the files they are uploaded to the server using already prepared names from db. At this stage, something goes wrong. HTML code of the page is trimmed to. Tell me, what could be the reason? There are no commands that can cut the code, I set error_reporting (E_ALL), nothing. What is strange in an absolutely similar way on this page you can create an article, also using two forms, differs only in the fact that the collection loads the cover and an array of photos, the length of which depends on the indicated number in the form, and the article only contains photos for preview. Articles are normally added without any problems.

Here is the source code for the pages:

<?php session_start(); if(isset($_POST['new_col']) || isset($_POST['create_article'])){ $_SESSION['auth'] = "completed"; } if($_SESSION['auth'] == "completed"){ echo '<font color="green">Авторизация ΠΏΡ€ΠΎΡˆΠ»Π° ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ</font>'; }else { echo '<font color="red" size="5vh"><p align="center" style="margin-top: 20vh"><b>ΠžΡ‚ΠΊΠ°Π· Π² доступС.</b></p></font> <br><font color="red" size="4vh"><p align="center">Π’Ρ‹ Π½Π΅ Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·ΠΎΠ²Π°Π»ΠΈΡΡŒ.</p></font>'; $html = preg_replace('#<div id="admin_panel">(.*?)</div>#', '', $html); } require('includes/config.php'); $last_collection = mysqli_query($connection, "SELECT * FROM `collections` ORDER BY `id` DESC LIMIT 1"); $last_col = mysqli_fetch_assoc($last_collection); $last_article = mysqli_query($connection, "SELECT * FROM `articles` ORDER BY `id` DESC LIMIT 1"); $last_art = mysqli_fetch_assoc($last_article); ?> <!DOCTYPE html> <html> <head> <title>Admin tools | Borys Andresiuk</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" type="text/css" href="css/admin_tools.css"> <link rel="stylesheet" type="text/css" href="../css/screen_16x10.css"> <link rel="stylesheet" type="text/css" href="../css/screen_4x3.css"> <link rel="stylesheet" type="text/css" href="../css/screen_9x16.css"> <script type="text/javascript" src="js/jquery-3.3.1.slim.js"></script> <script type="text/javascript" src="js/admin_tools.js"></script> <script type="text/javascript" src="js/create_check.js"></script> </head> <body> <main id="admin_panel" <?php if($_SESSION['auth'] != "completed"){echo 'style="display: none"';} if(isset($_POST['new_col']) || isset($_POST['create_article'])){$_SESSION['auth'] = "completed";}else{$_SESSION['auth'] = "";}?>> <div class="admin_title">ПанСль инструмСнтов Π°Π΄ΠΌΠΈΠ½Π°</div> <nav class="tools_menu"> <div class="tools_title">Π˜Π½ΡΡ‚Ρ€ΡƒΠΌΠ΅Π½Ρ‚Ρ‹:</div> <li><button class="tool_btn" id="collection_btn">Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ</button></li> <li><button class="tool_btn" id="article_btn">Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ ΡΡ‚Π°Ρ‚ΡŒΡŽ</button></li> <div class="translate_block"> <li><a href="https://translate.google.com/?hl=ru#ru/uk/" target="_blank"><button class="tool_btn translate" id="article_btn">ΠŸΠ΅Ρ€Π΅Π²ΠΎΠ΄ Π½Π° украинский</button></a></li> <li><a href="https://translate.google.com/?hl=ru" target="_blank"><button class="tool_btn translate" id="article_btn">ΠŸΠ΅Ρ€Π΅Π²ΠΎΠ΄ Π½Π° английский</button></a></li> </div> </nav> <?php if(isset($_POST['new_col'])){ $name = $_POST['name']; $name_rus = $_POST['name_rus']; $name_ukr = $_POST['name_ukr']; $location = $_POST['location']; $location_rus = $_POST['location_rus']; $location_ukr = $_POST['location_ukr']; $intro_text = $_POST['intro_text']; $intro_text_rus = $_POST['intro_text_rus']; $intro_text_ukr = $_POST['intro_text_ukr']; $name = trim($name); $name_rus = trim($name_rus); $name_ukr = trim($name_ukr); $location = trim($location); $location_rus = trim($location_rus); $location_ukr = trim($location_ukr); $intro_text = trim($intro_text); $intro_text_rus = trim($intro_text_rus); $intro_text_ukr = trim($intro_text_ukr); $id = $last_col['id'] + 1; $date = date("Ymd"); $col_img = str_replace(" ", "_", mb_strtolower($name)) . ".jpg"; if( mysqli_query($connection, "INSERT INTO `collections` (`id`, `name`, `name_rus`, `name_ukr`, `date`, `location`, `location_rus`, `location_ukr`, `code`, `intro_text`, `intro_text_rus`, `intro_text_ukr`, `img`) VALUES ('".$id."', '".$name."', '".$name_rus."', '".$name_ukr."', '".$date."', '".$location."', '".$location_rus."', '".$location_ukr."', '".$id."', '".$intro_text."', '".$intro_text_rus."', '".$intro_text_ukr."', '".$col_img."')") ){ $db_updated = true; }else { $db_updated = false; } $ph_quantity = trim($_POST['ph_quantity']); for($i = 1; $i <= $ph_quantity; $i++){ $ph_img = str_replace(" ", "_", mb_strtolower($name)) . $i .".jpg"; mysqli_query($connection, "INSERT INTO `photos` (`collection_id`, `img`, `code`, `location`, `location_rus`, `location_ukr`, `big`) VALUES ('".$id."', '".$ph_img."', '".$i."', '".$location."', '".$location_rus."', '".$location_ukr."', '0')"); } $countries_filters = mysqli_query($connection, "SELECT * FROM `countries`"); if(strpos($location, ",") !== false){ $cur_contry = mb_substr($location, 0, strpos($location, ",")); }else { $cur_contry = $location; } $c_exists = false; while($country = mysqli_fetch_assoc($countries_filters)){ if($cur_contry == $country['name']){ $c_exists = true; exit; } } if(!$c_exists){ if(strpos($location_rus, ",") !== false){ $cur_contry_rus = mb_substr($location_rus, 0, strpos($location_rus, ",")); }else { $cur_contry_rus = $location_rus; } if(strpos($location_ukr, ",") !== false){ $cur_contry_ukr = mb_substr($location_ukr, 0, strpos($location_ukr, ",")); }else { $cur_contry_ukr = $location_ukr; } if( mysqli_query($connection, "INSERT INTO `countries` (`name`, `name_rus`, `name_ukr`) VALUES ('".$cur_contry."', '".$cur_contry_rus."', '".$cur_contry_ukr."')") ){ $db_updated = true; }else { $db_updated = false; } } } if(isset($_POST['create_article'])){ $title = $_POST['title']; $title_rus = $_POST['title_rus']; $title_ukr = $_POST['title_ukr']; $text = $_POST['text']; $text_rus = $_POST['text_rus']; $text_ukr = $_POST['text_ukr']; $title = trim($title); $title_rus = trim($title_rus); $title_ukr = trim($title_ukr); $text = trim($text); $text_rus = trim($text_rus); $text_ukr = trim($text_ukr); $art_id = $last_art['id'] + 1; $art_date = date("Ymd"); $art_img = "ev" . $art_id . ".jpg"; if( mysqli_query($connection, "INSERT INTO `articles` (`id`, `img`, `text`, `text_rus`, `text_ukr`, `title`, `title_rus`, `title_ukr`, `date`) VALUES ('".$art_id."', '".$art_img."', '".$text."', '".$text_rus."', '".$text_ukr."', '".$title."', '".$title_rus."', '".$title_ukr."', '".$art_date."')") ){ $art_updated = true; }else { $art_updated = false; } } ?> <div class="create_form" id="create_collection_form"> <form action="admin_tools_page.php" method="POST"> <div class="form_title">Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ</div> <label for="name_rus" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>русском</b></label> <input type="text" name="name_rus" id="name_rus" class="form_input"> <label for="name" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>английском</b></label> <input type="text" name="name" id="name" class="form_input"> <label for="name_ukr" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>украинском</b></label> <input type="text" name="name_ukr" id="name_ukr" class="form_input"> <label for="location_rus" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ мСсто создания ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>русском</b></label> <input type="text" name="location_rus" id="location_rus" class="form_input"> <label for="location" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ мСсто создания ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>английском</b></label> <input type="text" name="location" id="location" class="form_input"> <label for="location_ukr" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ мСсто создания ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>украинском</b></label> <input type="text" name="location_ukr" id="location_ukr" class="form_input"> <label for="intro_text_rus" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΎΠ·Π½Π°ΠΊΠΎΠΌΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ тСкст ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>русском</b></label> <textarea name="intro_text_rus" id="intro_text_rus" class="form_textarea"></textarea> <label for="intro_text" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΎΠ·Π½Π°ΠΊΠΎΠΌΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ тСкст ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>английском</b></label> <textarea name="intro_text" id="intro_text" class="form_textarea"></textarea> <label for="intro_text_ukr" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΎΠ·Π½Π°ΠΊΠΎΠΌΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ тСкст ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π½Π° <b>украинском</b></label> <textarea name="intro_text_ukr" id="intro_text_ukr" class="form_textarea"></textarea> <label for="ph_quantity" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ количСство Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΠΉ Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ</label> <input type="text" name="ph_quantity" id="ph_quantity" class="form_input"> <input type="submit" name="new_col" id="create_collection" value="Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ" class="create_btn"> </form> </div> <div class="create_form" id="img_col_form" <?php if(isset($_POST['new_col'])){echo 'style="display: block"';}?>> <?php if($db_updated){echo '<font color="green">ΠšΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡ ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ создана, Π²Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΠΈ</font>';}else{echo '<font color="red" size="4vh">Π’ΠΎΠ·Π½ΠΈΠΊΠ»ΠΈ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹ ΠΏΡ€ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΈ ΠΊ Π±Π°Π·Π΅ Π΄Π°Π½Π½Ρ‹Ρ….</font>';}?> <form method="POST" action="includes/upload_img.php" enctype="multipart/form-data"> <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="images"> <div class="form_title">Π”ΠΎΠ±Π°Π²Π΅Π½ΠΈΠ΅ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΠΉ</div> <label for="col_wrap" class="form_label">Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΡŽ для ΠΎΠ±Π»ΠΎΠΆΠΊΠΈ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ</label> <label for="col_wrap"> <input type="file" name="col_wrap" id="col_wrap" class="file"> </label> <label for="col_photos[]" class="form_label">ДобавляйтС ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΌΡƒ Ρ„ΠΎΡ‚ΠΎ Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ</label> <?php for($i = 0; $i < $_POST['ph_quantity']; $i++){ ?> <label> <input type="file" name="col_photos[]" class="file"> <span class="ph_big"> <label for="big">Π‘ΠΎΠ»ΡŒΡˆΠ°Ρ</label> <input type="checkbox" name="big<?php echo $i + 1?>"> </span> </label> <?php } ?> <input type="submit" name="col_img_post" value="ΠžΡ‚ΠΏΡ€Π°Π²Ρ‚ΠΈΡŒ" class="create_btn"> </form> </div> <div class="create_form" id="create_article_form"> <form action="admin_tools_page.php" method="POST"> <div class="form_title">Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ ΡΡ‚Π°Ρ‚ΡŒΡŽ</div> <label for="title_rus" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° <b>русском</b></label> <input type="text" name="title_rus" id="title_rus" class="form_input"> <label for="title" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° <b>английском</b></label> <input type="text" name="title" id="title" class="form_input"> <label for="title_ukr" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° <b>украинском</b></label> <input type="text" name="title_ukr" id="title_ukr" class="form_input"> <label for="text_rus" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ тСкст ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° <b>русском</b></label> <textarea name="text_rus" id="text_rus" class="form_textarea"></textarea> <label for="text" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ тСкст ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° <b>английском</b></label> <textarea name="text" id="text" class="form_textarea"></textarea> <label for="text_ukr" class="form_label">Π’Π²Π΅Π΄ΠΈΡ‚Π΅ тСкст ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° <b>украинском</b></label> <textarea name="text_ukr" id="text_ukr" class="form_textarea"></textarea> <input type="submit" name="create_article" id="create_article" value="Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ" class="create_btn"> </form> </div> <div class="create_form" id="img_art_form" <?php if(isset($_POST['create_article'])){echo 'style="display: block"';}?>> <?php if($art_updated){echo '<font color="green">Π‘Ρ‚Π°Ρ‚ΡŒΡ ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ создана, Π²Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΡŽ</font>';}else{echo '<font color="red" size="4vh">Π’ΠΎΠ·Π½ΠΈΠΊΠ»ΠΈ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹ ΠΏΡ€ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΈ ΠΊ Π±Π°Π·Π΅ Π΄Π°Π½Π½Ρ‹Ρ….</font>';}?> <form method="POST" action="includes/upload_img.php" enctype="multipart/form-data"> <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="images"> <div class="form_title">Π”ΠΎΠ±Π°Π²Π΅Π½ΠΈΠ΅ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΠΉ</div> <label for="art_img" class="form_label">Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΡŽ для ΠΎΠ±Π»ΠΎΠΆΠΊΠΈ ΡΡ‚Π°Ρ‚ΡŒΠΈ</label> <label for="art_img"> <input type="file" name="art_img" id="art_img" class="file"> </label> <input type="submit" name="art_img_post" value="ΠžΡ‚ΠΏΡ€Π°Π²Ρ‚ΠΈΡŒ" class="create_btn"> </form> </div> </main> </body> <?php require('includes/close_db.php'); ?> </html> 

Here's how it is clipped:

  <html> <head> <title>Admin tools | Borys Andresiuk</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" type="text/css" href="css/admin_tools.css"> <link rel="stylesheet" type="text/css" href="../css/screen_16x10.css"> <link rel="stylesheet" type="text/css" href="../css/screen_4x3.css"> <link rel="stylesheet" type="text/css" href="../css/screen_9x16.css"> <script type="text/javascript" src="js/jquery-3.3.1.slim.js"></script> <script type="text/javascript" src="js/admin_tools.js"></script> <script type="text/javascript" src="js/create_check.js"></script> </head> <body> <main id="admin_panel" > <div class="admin_title">ПанСль инструмСнтов Π°Π΄ΠΌΠΈΠ½Π°</div> <nav class="tools_menu"> <div class="tools_title">Π˜Π½ΡΡ‚Ρ€ΡƒΠΌΠ΅Π½Ρ‚Ρ‹:</div> <li><button class="tool_btn" id="collection_btn">Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ</button></li> <li><button class="tool_btn" id="article_btn">Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ ΡΡ‚Π°Ρ‚ΡŒΡŽ</button></li> <div class="translate_block"> <li><a href="https://translate.google.com/?hl=ru#ru/uk/" target="_blank"><button class="tool_btn translate" id="article_btn">ΠŸΠ΅Ρ€Π΅Π²ΠΎΠ΄ Π½Π° украинский</button></a></li> <li><a href="https://translate.google.com/?hl=ru" target="_blank"><button class="tool_btn translate" id="article_btn">ΠŸΠ΅Ρ€Π΅Π²ΠΎΠ΄ Π½Π° английский</button></a></li> </div> </nav> </body> </html> 

I would be grateful for any help.

  • phpfaq.ru/debug - Ipatiev
  • did not try to write the code more compactly, without kopipasta? $fields = ['name', 'name_rus', ..] ; foreach($fields as $f){ $values[$f] = trim($_POST[$field]); } $fields = ['name', 'name_rus', ..] ; foreach($fields as $f){ $values[$f] = trim($_POST[$field]); } . + there is more about prepared expressions for insertion into the database, etc. - teran
  • </body></html> the browser in the inspector is probably finished by you. They are probably not in the source text of the page. Perhaps because in one of the cycles, for some reason, you exit instead of break - teran
  • Yes, you are right, they are not in the source code, I will try to fix exit. - Mikhail Kosyuk
  • @teran You are absolutely right, everything works with break, after exit script execution stopped. - Mikhail Kosyuk

0