Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `<?php
- //set data in input text
- $id = "";
- $declarant = "";
- $object_analytic = "";
- $collecteur = "";
- if (isset($_POST['search'])) {
- // connect to database (mysql)
- try {
- $pdoConnect = new PDO("mysql:host=localhost;dbname=xxxxx;charset=utf8", "root", "");
- $pdoConnect->setAttribute(PDO::ATTR_ERRMODE,
- PDO::ERRMODE_EXCEPTION);
- echo "connected successfully";
- } catch (PDOException $e) {
- echo "The connection is failed: " . $e->getMessage();
- }
- // to search id
- $id = $_POST['id'];
- $declarant = $_POST['declarant'];
- $object_analytic = $_POST['object-analytic'];
- $collecteur = $_POST['collecteur'];
- // search mysql query
- $pdoQuery = "SELECT * FROM filter
- WHERE id = :id, declarant = :declarant, object-
- analytic =
- :object-analytic, collecteur = :collecteur
- ";
- $pdoResult = $pdoConnect->prepare($pdoQuery);
- $pdoExecute = $pdoResult->execute(array(
- ':id' => $id,
- ':declarant' => $declarant,
- ':object-analytic' => $object_analytic,
- ':collecteur' => $collecteur
- ));
- $pdoResult->fetch(PDO::FETCH_OBJ);
- if ($pdoExecute) {
- // if id exist, show data in the table
- if ($pdoResult->rowCount() > 0) {
- foreach ($pdoResult as $row) {
- $id = $row['id'];
- $declarant = $row['declarant'];
- $object_analytic = $row['object-analytic'];
- $collecteur = $row['collecteur'];
- }
- }
- // if the id is not exist, show a message
- else {
- echo "No data with this ID";
- }
- } else {
- echo "Error, data is not inserted";
- }
- }
- ?>`
- `<form action="index.php" method="post">
- <div class="form-group">
- <input type="text" name="valueToSearch"
- placeholder="Value To Search"><br><br>
- <input type="submit" name="search" value="Filter">
- </div>
- <table class="table table-bordered table-striped">
- <tr>
- <th>Id</th>
- <th>Declarant</th>
- <th>Object analytic</th>
- <th>Collecteur</th>
- </tr>
- <?php foreach ($pdoResult as $row): ?>
- <tr>
- <td><?php echo $row->id; ?></td>
- <td><?php echo $row->declarant; ?></td>
- <td><?php echo $row->object_analytic; ?></td>
- <td><?php echo $row->collecteur; ?></td>
- </tr>
- <?php endforeach; ?>
- </table>
- </form>`
Add Comment
Please, Sign In to add comment