Guest User

Untitled

a guest
Dec 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. `<?php
  2.  
  3. //set data in input text
  4.  
  5. $id = "";
  6. $declarant = "";
  7. $object_analytic = "";
  8. $collecteur = "";
  9.  
  10. if (isset($_POST['search'])) {
  11.  
  12. // connect to database (mysql)
  13. try {
  14. $pdoConnect = new PDO("mysql:host=localhost;dbname=xxxxx;charset=utf8", "root", "");
  15. $pdoConnect->setAttribute(PDO::ATTR_ERRMODE,
  16. PDO::ERRMODE_EXCEPTION);
  17.  
  18. echo "connected successfully";
  19.  
  20. } catch (PDOException $e) {
  21. echo "The connection is failed: " . $e->getMessage();
  22. }
  23.  
  24. // to search id
  25. $id = $_POST['id'];
  26. $declarant = $_POST['declarant'];
  27. $object_analytic = $_POST['object-analytic'];
  28. $collecteur = $_POST['collecteur'];
  29.  
  30. // search mysql query
  31.  
  32. $pdoQuery = "SELECT * FROM filter
  33. WHERE id = :id, declarant = :declarant, object-
  34. analytic =
  35. :object-analytic, collecteur = :collecteur
  36.  
  37.  
  38. ";
  39.  
  40.  
  41. $pdoResult = $pdoConnect->prepare($pdoQuery);
  42.  
  43. $pdoExecute = $pdoResult->execute(array(
  44. ':id' => $id,
  45. ':declarant' => $declarant,
  46. ':object-analytic' => $object_analytic,
  47. ':collecteur' => $collecteur
  48.  
  49. ));
  50.  
  51. $pdoResult->fetch(PDO::FETCH_OBJ);
  52.  
  53.  
  54. if ($pdoExecute) {
  55.  
  56. // if id exist, show data in the table
  57.  
  58. if ($pdoResult->rowCount() > 0) {
  59.  
  60. foreach ($pdoResult as $row) {
  61.  
  62. $id = $row['id'];
  63. $declarant = $row['declarant'];
  64. $object_analytic = $row['object-analytic'];
  65. $collecteur = $row['collecteur'];
  66. }
  67. }
  68.  
  69. // if the id is not exist, show a message
  70.  
  71. else {
  72. echo "No data with this ID";
  73. }
  74. } else {
  75. echo "Error, data is not inserted";
  76. }
  77. }
  78.  
  79. ?>`
  80.  
  81. `<form action="index.php" method="post">
  82. <div class="form-group">
  83. <input type="text" name="valueToSearch"
  84. placeholder="Value To Search"><br><br>
  85. <input type="submit" name="search" value="Filter">
  86. </div>
  87. <table class="table table-bordered table-striped">
  88. <tr>
  89. <th>Id</th>
  90. <th>Declarant</th>
  91. <th>Object analytic</th>
  92. <th>Collecteur</th>
  93. </tr>
  94. <?php foreach ($pdoResult as $row): ?>
  95. <tr>
  96.  
  97. <td><?php echo $row->id; ?></td>
  98. <td><?php echo $row->declarant; ?></td>
  99. <td><?php echo $row->object_analytic; ?></td>
  100. <td><?php echo $row->collecteur; ?></td>
  101.  
  102.  
  103. </tr>
  104. <?php endforeach; ?>
  105. </table>
  106. </form>`
Add Comment
Please, Sign In to add comment