Передать id строки со страницы с результатами поиска на страницу редактирования и вывести в инпуты

Требуется со страницы с поиском при нажатие на кнопку редактирования для определенной строки -> сохранить id строчки БД и на странице редактирования вывести остальные атрибуты в инпуты(id не нужно выводить). update.php закинул на всякий случай.В дальнейшем редактировать. Может кто нибудь подсказать, что мне нужно сделать/изменить?

findoper.php

<?php
session_start();
require_once "vendor/connect.php";
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="style/style.css">
    <script src="script.js"></script>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Научно-справочная библиотека</title>
</head>

<body>
    <style>
        td {
            font-size: large;
        }

        .wrapper {
            position: relative;
            background-image: url('6.jpg');
            background-size: cover;
            background-position: center;
            height: 200px;

        }
    </style>
    <div class="wrapper">
        <?php
        if (isset($_SESSION['user'])) {
            echo "<h3>" . $_SESSION['user']['login'], "," . $_SESSION['user']['role'] . ".</h3>";
        }
        $_SESSION['id'] = $id;
        ?>
        <form name="search" method="POST" action="findoper.php">
            <div style="display:flex; flex-direction: row; justify-content: center; align-items: center;">
                <div class="label">
                    <div class="info">
                        <input type="text" id="id" name="id" hidden>
                        <label>Название:</label>
                        <input type="text" style="border: 1px solid black" name="search[title]">
                    </div>
                </div>
                <div class="label">
                    <div class="info">
                        <label>Автор:</label>
                        <input type="text" style="border: 1px solid black" name="search[author]">
                    </div>
                </div>
                <div class="label">
                    <div class="info">
                        <label>Под редакцией:</label>
                        <input type="text" style="border: 1px solid black" name="search[compedit]">
                    </div>
                </div>
                <div class="label">
                    <div class="info">
                        <label>Год:</label>
                        <input type="text" style="border: 1px solid black" name="search[year]" style="height:30px; width:60px;">
                    </div>
                </div>
                <div class="info">
                    <input type="submit" name="submit" value="Поиск" style="height:30px; width:120px; background-color: white">
                </div>
        </form>
        <div class="info">
            <form action="mainpageoper.php">
                <input type="submit" name="Back" value="Назад" style="height:30px; width:120px; background-color: white">
            </form>
        </div>
        <br>
        <br>
        <div class="info">
            <form action="vendor/logout.php">
                <input type="submit" name="Logout" value="Выход" style="height:30px; width:120px; background-color: white">
            </form>
        </div>
    </div>

    <?php

    $queryCondition = "";
    if (!empty($_POST)) {
        $submitForm = $_POST["submit"];
        foreach ($_POST["search"] as $key => $value) {
            if (isset($value)) {
                if (empty($queryCondition)) {
                    $queryCondition = " WHERE ";
                } else {
                    $queryCondition .= " AND ";
                }
                $queryCondition .= "$key LIKE '%" . $value . "%'";
            }
        }
    }
    $sql = "SELECT `id`,`title`, `author`,`place`, `year`, `publisher`, `compedit`,`countpages`,`archive`,`BBK`,`inventnumber`,`numbinstances`,`lasttaker` FROM infprintedit " . $queryCondition;
    $result = mysqli_query($connect, $sql);
    $res = mysqli_fetch_all($result, MYSQLI_ASSOC);

    echo "<table><tr><th>ID</th><th>Название</th><th>Авторы и составители</th><th>Год</th><th>Место</th><th>Издательство</th><th>Под редакцией</th><th>Количество страниц</th><th>Архив</th><th>ББК</th><th>Инвентарный номер</th><th>Количество экземпляров</th><th>Кто последний пользовался</th><th>Действие</th></tr>";
    foreach ($res as $row) {
    ?>
        <tr>
            <td>
                <?php echo $row["id"]; ?>
            </td>
            <td>
                <?php echo $row["title"]; ?>
            </td>
            <td>
                <?php echo $row["author"]; ?>
            </td>
            <td>
                <?php echo $row["year"]; ?>
            </td>
            <td>
                <?php echo $row["place"]; ?>
            </td>
            <td>
                <?php echo $row["publisher"]; ?>
            </td>
            <td>
                <?php echo $row["compedit"]; ?>
            </td>
            <td>
                <?php echo $row["countpages"]; ?>
            </td>
            <td>
                <?php echo $row["archive"]; ?>
            </td>
            <td>
                <?php echo $row["BBK"]; ?>
            </td>
            <td>
                <?php echo $row["inventnumber"]; ?>
            </td>
            <td>
                <?php echo $row["numbinstances"]; ?>
            </td>
            <td>
                <?php echo $row["lasttaker"]; ?>
            </td>
            <td>
            <a href="edit.php?id=<?php echo $row['id']; ?>">Редактировать</a>
            </td>
        </tr>
    <?
    }
    echo "</table >";
    $result->free();
    ?>
</body>

</html>

edit.php

<?php
session_start();
require_once "vendor/connect.php";
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="style/style.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Научно-справочная библиотека</title>
</head>

<body>
    <style>
        body {
            background: url(6.jpg);
        }

        label {
            width: 100px;
            margin-right: 50px;
            text-align: right;
            float: left;
        }
    </style>
    <form action="vendor/update.php" method="POST">
        <?php
        if (isset($_SESSION['user'])) {
            echo "<h3>" . $_SESSION['user']['login'], "," . $_SESSION['user']['role'] . ".</h3>";
        }

        // Получаем значение параметра id из URL
        $id = $_GET['id'];
        // Выполняем запрос к БД для получения данных строки по ее id
        $query = "SELECT * FROM `infprintedit` WHERE id = $id";
        $result = mysqli_query($connect, $query);

        // Обрабатываем результат запроса
        if ($result && mysqli_num_rows($result) > 0) {
            $row = mysqli_fetch_assoc($result);
        
            // Здесь можно использовать значения атрибутов строки для редактирования

        }        
        echo '<pre>';
        var_dump($query);
        echo '</pre>';
        ?>
        

        <form method="POST" action="/vendor/update.php">
            <div style="display:flex;justify-content: center; flex-direction: row;  align-items: center;flex-flow: column nowrap">
                <div class="label">
                <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                    <label>Название:</label>
                    <td><input type="text" name="title" value="<?php echo $row['title']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Автор:</label>
                    <td><input type="text" name="author" value="<?php echo $row['author']; ?>"  style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Редакция:</label>
                    <td><input type="text" name="compedit" value="<?php echo $row['compedit']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Место:</label>
                    <td><input type="text" name="place" value="<?php echo $row['place']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Год:</label>
                    <td><input type="text" name="year" value="<?php echo $row['year']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Издательство:</label>
                    <td><input type="text" name="publisher" value="<?php echo $row['publisher']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Количество страниц:</label>
                    <td><input type="text" name="countpages" value="<?php echo $row['countpages']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Архив:</label>
                    <td><input type="text" name="archive" value="<?php echo $row['archive']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>ББК:</label>
                    <td><input type="text" name="BBK" value="<?php echo $row['BBK']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Инвентарный №:</label>
                    <td><input type="text" name="inventnumber" value="<?php echo $row['inventnumber']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Количество экземпляров:</label>
                    <td><input type="text" name="numbinstances" value="<?php echo $row['numbinstances']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <div class="label">
                    <label>Последний взял:</label>
                    <td><input type="text" name="lasttaker" value="<?php echo $row['lasttaker']; ?>" style="width: 1000px;height:40px"></td>
                </div>
                <input type="submit" name="Save" value="Сохранить" class="button" style="height:40px; width:600px; background-color: white">
        </form>
        <br>
        <form action="findoper.php">
            <input type="submit" name="back" value="Назад" class="button" style="height:40px; width:600px; background-color: white">
        </form>
        </div>

</body>

</html>

update.php

<?php
session_start();
require_once 'connect.php';
$id = $_GET['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$place = $_POST['place'];
$year = $_POST['year'];
$publisher = $_POST['publisher'];
$compedit = $_POST['compedit'];
$countpages = $_POST['countpages'];
$archive = $_POST['archive'];
$BBK = $_POST['BBK'];
$inventnumber = $_POST['inventnumber'];
$numbinstances = $_POST['numbinstances'];
$lasttaker = $_POST['lasttaker'];
$sql = ("UPDATE infprintedit SET title='$title',author='$author',year ='$year',place ='$place',publisher='$publisher',compedit='$compedit',countpages='$countpages',archive='$archive',BBK='$BBK',inventnumber='$inventnumber',numbinstances='$numbinstances',lasttaker='$lasttaker' WHERE id='$id'");
$result = mysqli_query($connect, $sql);
var_dump($result);


Ответы (0 шт):