如果未调用isset语句

时间:2019-12-03 20:01:11

标签: php html forms

在按作者或价格订购(ASC)之前,我试图通过单击任一按钮重新加载下面显示的表格。似乎根本没有按下按钮,并且想知道是否有人可以帮助我。

我所拥有的是将两个按钮以一种形式提交给自己,并将其提交到同一页面。我一直在用isset if语句等待这些按钮。但是if语句似乎永远不会触发,因为您可以看到我在其中显示了回显,从而在屏幕上显示了

/** This is checking which buttons got hit */
if(isset($_POST['btn1'])){
    echo "getting here!!";
    $query = "SELECT * FROM books ORDER BY author ASC;";
    $result = $mysqli->query($query);
    $num_results = $result->num_rows;
}

if(isset($_POST['btn2'])){
    echo "Getting here!!!!";
    $query = "SELECT * FROM books ORDER BY price ASC;";
    $result = $mysqli->query($query);
    $num_results = $result->num_rows;
}
    ?>
    <html>
    <head>
        <link rel="stylesheet" type="text/css" href="MainStyleSheet.css">
        <link rel="stylesheet" type="text/css" href="bootstrap-4.3.1/dist/css/bootstrap.css">
        <script rel="script" type="text/css" src="bootstrap-4.3.1/dist/js/bootstrap.js"></script>
        <title>Bookorama</title>
    </head>
    <body>
    <nav class="navbar navbar-light bg-light">
        <a class="navbar-brand">Navbar</a>
        <div class="divNavClass">
            <a class="aLinks">Book Inventory</a>
            <a class="aLinks">Contact</a>
            <a class="">Login</a>
        </div>
    </nav>
    <div class="customCss">
        <h2>CIS Book Inventory</h2>
        <h5>Number of books found <?php echo "$num_results"; ?></h5>
    </div>
    <!-- Main container -->
    <div class="container">
        <div class="container">
            <!-- Container for the table with the fluid container -->
            <div class="container-fluid">
                <div class="outer">
                    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
                        <button id="btn1" name="btn1" class="inner btn btn-primary" type="button">Sort By Author</button>
                        <button id="btn2" name="btn2" class="inner btn btn-primary" type="button">Sort By Price</button>
                    </form>
                </div>
                <table class="table">
                    <tr>
                        <th scope="col">ISBN</th>
                        <th scope="col">Author</th>
                        <th scope="col">Title</th>
                        <th scope="col">Price</th>
                    </tr>
                    <!-- This is where the sql loop starts -->
                    <?php
                    //Below is what dynamically produces the table.
                    while($row = mysqli_fetch_assoc($result)) {
                        echo '<tr><td scope="row">' . $row['isbn'] . '</td><td scope="row">' . $row['author'] . '</td><td scope="row">' . $row['title'] . '</td><td scope="row">' . $row['price'] . '</td></tr>';
                    }
                    ?>
                    <!-- This is where the sql loop ends -->
                </table>
            </div>
        </div>
    </div>
    </body>
    </html>
<?php

0 个答案:

没有答案