Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. <div class="container-fluid">
  2. <form class="form col-md-8" id="form_Show" role="form" form action="Show.php" method="post">
  3. <legend>Show Customers table</legend>
  4. <h5>Put any characters in Customer's name to search the data</h5>
  5. <div class="form-group">
  6. <label for="Cstm_name" class="col-sm-2">Customer Name</label>
  7. <div class="col-sm-4">
  8. <input type="text" class="form-control" name="show" id="show" placeholder="e.g) A, L or J">
  9. </div>
  10. <div class="row"></div>
  11. <div class="form-group">
  12. <div class="col-sm-offset-2 col-sm-10">
  13. <button type="submit" class="btn btn-primary">Save</button>
  14. </div>
  15. </div>
  16. </div>
  17. </form>
  18. </div>
  19.  
  20. <?php
  21. $host = "localhost";
  22. $user = "";
  23. $password = "";
  24. $database = "";
  25.  
  26. mysql_connect($host,$user,$password) or die("mysql_connect error");
  27. mysql_select_db($database) or die("mysql_select_db error");
  28. if(isset($_POST['show'])){
  29. $search = $_POST['show'];
  30. $search = preg_replace("#[^0-9a-z]#i","",$search);
  31. $sql = mysql_query("SELECT * FROM Customers") or die("could not search");
  32. ?>
  33. <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
  34. <thead>
  35. <tr>
  36. <th>id</th>
  37. <th>Name</th>
  38. <th>Adress</th>
  39. <td>Cell phone</td>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. <?php while( $row = mysql_fetch_array( $sql ) ){
  44. echo
  45. "<tr>
  46. <td>{$row['Cstm_id']}</td>
  47. <td>{$row['Cstm_name']}</td>
  48. <td>{$row['Cstm_addrs']}</td>
  49. <td>{$row['CCell_no']}</td>
  50. </tr>n";
  51. }
  52. ?>
  53. </tbody>
  54. </table>
  55.  
  56. <?php
  57. $link = new mysqli('localhost','root','admin','demo1');
  58. if($link->connect_error){
  59. die("Connection Failed".$link->connect_error);
  60. }
  61. ?>
  62. <!DOCTYPE html>
  63. <html lang="en">
  64. <head>
  65. <title></title>
  66. <meta charset="utf-8">
  67. <meta name="viewport" content="width=device-width, initial-scale=1">
  68. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  69. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  70. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  71. </head>
  72. <body>
  73.  
  74. <div class="container">
  75. <br><br>
  76. <div class="col-md-5">
  77. <form action="" method="get">
  78. <div class="form-group">
  79. <input type="text" name="search" class="form-control" placeholder="Search Customer Name Here..."/>
  80. </div>
  81. <div class="form-group">
  82. <input type="submit" name="search_btn" class="btn btn-default" value="Search"/>
  83. </div>
  84. </form>
  85.  
  86. <?php
  87. if(isset($_GET['search_btn'])){
  88.  
  89. $search_var = $_GET['search'];
  90.  
  91. $sql = "SELECT * FROM search_form WHERE customer_name LIKE '%".$search_var."%'";
  92. if($res = $link->query($sql)){
  93.  
  94. ?>
  95. <table class="table table-striped">
  96. <thead>
  97. <tr>
  98. <th>Custmer id</th>
  99. <th>Customer Name</th>
  100. </tr>
  101. </thead>
  102. <tbody>
  103. <?php
  104. if($res->num_rows > 0){
  105.  
  106. while($row = $res->fetch_assoc()){
  107. ?>
  108. <tr>
  109. <td><?php echo $row['id'];?></td>
  110. <td><?php echo $row['customer_name'];?></td>
  111. </tr>
  112. <?php
  113. }
  114. }
  115. else
  116. {
  117. ?>
  118. <tr>
  119. <td colspan="2">Not Found<?php echo $link->error;?></td>
  120. </tr>
  121. <?php
  122. }
  123. ?>
  124. </tbody>
  125. </table>
  126. <?php
  127. }
  128. else
  129. {
  130. echo "Failed".$sql;
  131. }
  132. }
  133. ?>
  134. </div>
  135. </div>
  136.  
  137. </body>
  138. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement