将选中的行从html复选框插入数据库,并从搜索结果插入php

时间:2018-09-26 18:04:05

标签: php html

我正在尝试从显示在网页上的搜索查询生成的表中插入代码。用户可以检查表中的一行,然后从此处应用按钮应将信息提交到mysql数据库。 我已经在网上寻找有关此问题的更多信息,但找不到适合这种情况的任何信息。我已经尝试过为每个循环使用带复选框的数组,但是它不起作用。在代码php中,用户可以搜索db。我需要一种将选中的行放入数据库表的方法。

<div class="SearchBar">

    <form action="volHome.php?go" method="POST" id="searchForm">

        <input type="text" name="name" placeholder="Search..">
        <input type="submit" name="submit" value="Submit">

        <table>
            <tr>
                <th>Description</th>
                <th>Start Date</th>
                <th>End Date</th>
                <th>City</th>
                <th>Organization</th>
            </tr>

            <?php
            try {
                $conn = new PDO('mysql:host=localhost;dbname=finalproject;port=3306;', 'root', '');
            }
            catch (Exception $e) {
                echo 'Not Connected: ', $e->getmessage();
                die('not connected');
            }

            if (isset($_POST['submit'])) {
                if (isset($_GET['go'])) {
                    //  echo"<p>If statement being entered</p>";
                    $name = $_POST['name'];

                    $sql = "select o.City, Description, endDate, startDatee, org.Name from opportunity o join organizations org on o.O_ID = org.O_ID where o.city like '%$name%' or Description like '%$name%' or org.Name like '%$name%'";

                    $stmt = $conn->prepare($sql);
                    $stmt->execute();

                    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                        echo '<tr>';
                        echo '<td><input type="checkbox" onclick="getRow(this)"/>', $row['Description'], '</td>';
                        echo '<td>', $row['startDatee'], '</td>';
                        echo '<td>', $row['endDate'], '</td>';
                        echo '<td>', $row['City'], '</td>';
                        echo '<td>', $row['Name'], '</td>';
                        echo '</tr>';

                    }

                }
            }

            ?>


        </table>
    </form>
</div>

0 个答案:

没有答案
相关问题