there is a script, it fulfills one condition before another, the essence of this is to select checkboxes and change values or delete the html form here. The problem is that only deletion is performed.
<form action="remove.php" name="multiform" id="multiform" method="POST" enctype="multipart/form-data"> <label class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input chk-all" value="0" name="g1[]"> <span class="custom-control-indicator"></span> <span class="custom-control-description">выделить все</span> </label> | <button type="submit" name="del">Удалить выделенные</button> | | <button type="submit" name="publication">Опуликовать</button> | | <button type="submit" name="shootPublcation">Снять пуликовать</button> | <br> <hr> <div id="bg-danger"></div> <?php require_once($_SERVER['DOCUMENT_ROOT'] . '/bd.php'); $result = $pdo->prepare('SELECT DISTINCT id, email, fullName, number_Phone, imgRealtorSmall, fileNameSmall FROM realtor ORDER BY id DESC'); $result->execute(); if($result->rowCount() > 0){ while ($myrow = $result->fetch(PDO::FETCH_ASSOC)){ $file = explode(',', $myrow['fileNameSmall']); foreach ($file as $key) { echo " <label class='custom-control custom-checkbox'> <input type='checkbox' class='custom-control-input' name='g1[]' value='".$myrow['id']."'> <span class='custom-control-indicator'></span> </label> <div class='row formBorder'> <div class='col-md-3'> <img src='../".$myrow['imgRealtorSmall'].$key."' style='background-size: cover; width: 130px; height: auto;'> </div> <div class='col-md-7 fullContactCompany'>ФИО: ".$myrow['fullName']."</div> <div class='col-md-7 fullContactCompany'>Емайл: ".$myrow['email']."</div> <div class='col-md-7 fullContactCompany'>Телефоны: ".$myrow['number_Phone']."</div><div class='col-md-2'><a href='https://rl76.online/crm/employees/cabinet.php?val=".$myrow['id']."' class='btn btn-primary'>Подронее</a></div> </div>"; } } } ?> </form> php handler itself
<?php $comma_separated = implode(",", $_POST['g1']); require_once($_SERVER['DOCUMENT_ROOT'] . '/bd.php'); if(!isset($_POST["publication"])) { $publication = "Опубликованно"; $sql = ('UPDATE realtor SET publication=:publication WHERE id IN (' . $comma_separated . ')'); $sql = $pdo->prepare($sql); $sql->bindParam(':publication', $publication, PDO::PARAM_STR); $sql->execute(); } if(!isset($_POST["del"])) { $oneArray = array_shift($_POST['g1']); unset($oneArray); $result = $pdo->prepare('SELECT DISTINCT img_Realtor, filename FROM realtor WHERE id IN (' . $comma_separated . ')'); $result->execute(array(':id' => $_POST['g1'])); if($result->rowCount() > 0){ while ($myrow = $result->fetch(PDO::FETCH_ASSOC)){ unlink("../".$myrow['img_Realtor'].$myrow['filename']); } } $sql = $pdo->prepare ('DELETE FROM realtor WHERE id IN (' . $comma_separated . ')'); $sql->execute(); if ($sql) { $ddd[] = "Риелтор удалён"; echo json_encode($ddd); } }