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.
$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, youexitinstead ofbreak- teran