Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. <form method="post" action="search.php">
  2. <div class="input-group has-success">
  3. <input id="btn-input" name="search" type="text" class="form-control input-md" placeholder="Please type the ID number of the user you want to update..." />
  4. <span class="input-group-btn">
  5. <button class="btn btn-success btn-md" id="btn-chat" type="submit">Search</button>
  6. </span>
  7. </div>
  8. </form>
  9. </div>
  10.  
  11.  
  12. <div class="col-md-6">
  13.  
  14. <form role="form">
  15.  
  16.  
  17. <div class="form-group">
  18. <label>username</label>
  19. <input class="form-control" placeholder="Placeholder">
  20. </div>
  21.  
  22. <div class="form-group">
  23. <label>Password</label>
  24. <input class="form-control">
  25. </div>
  26.  
  27.  
  28. <div class="form-group">
  29. <label>UserType</label>
  30. <input class="form-control">
  31. </div>
  32.  
  33. </form>
  34.  
  35. <?php
  36.  
  37. $conn = mysqli_connect("localhost", "root", "", "asset_inventory");
  38.  
  39. if($conn === false){
  40. die("ERROR: Could not connect. " . mysqli_connect_error());
  41. }
  42.  
  43.  
  44. $search = mysqli_real_escape_string($conn, $_POST['search']);
  45.  
  46.  
  47. $sql = "SELECT * FROM users WHERE user_id='$search'";
  48. $result = mysqli_query($conn, $sql);
  49.  
  50. if (mysqli_num_rows($result) > 0) {
  51.  
  52. while($row = mysqli_fetch_assoc($result)) {
  53.  
  54.  
  55. $name=$row['user_name'];
  56. $pass=$row['user_pass'];
  57. $type=$row['user_type'];
  58. }
  59.  
  60. } else {
  61. echo "0 results";
  62. }
  63.  
  64.  
  65. mysqli_close($conn);
  66. ?>
  67.  
  68. if (mysqli_num_rows($result) > 0)
  69. {
  70. while($row = mysqli_fetch_assoc($result))
  71. {
  72. $name=$row['user_name'];
  73. $pass=$row['user_pass'];
  74. $type=$row['user_type'];
  75. }
  76. }
  77. else
  78. {
  79. echo "0 results";
  80. }
  81.  
  82. <table>
  83.  
  84. <?php
  85. if (mysqli_num_rows($result) > 0)
  86. {
  87. while($row = mysqli_fetch_assoc($result))
  88. {
  89.  
  90. ?>
  91.  
  92. <tr>
  93. <td> <?php echo $name=$row['user_name']; ?> </td>
  94. <td> <?php echo $name=$row['user_pass']; ?> </td>
  95. <td> <?php echo $name=$row['user_type']; ?> </td>
  96. </tr>
  97.  
  98. <?php
  99. }
  100. }
  101. else
  102. {
  103. ?>
  104.  
  105. <tr>
  106. <td colspan="3">0 results</td>
  107. </tr>
  108.  
  109. <?php
  110. }
  111. ?>
  112.  
  113. </table>
  114.  
  115. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
  116. <script>
  117. $(function(){
  118. $(document).on("click", "#btn-chat", function(e) {
  119. e.preventDefault();
  120. //Built a url to send
  121. var info = $("#form").serialize();
  122. $.ajax({
  123. type: "POST",
  124. url: "search.php",
  125. data: info,
  126. success: function(result){
  127. //$('#respoondarea').load(location.href + '#respondarea');
  128. //$("#form")[0].reset();
  129. $('#respond').html(result);
  130. }
  131. });
  132. e.preventDefault();
  133. });
  134. });
  135.  
  136. </script>
  137. <form method="post" id="form" action="search.php">
  138. <div class="input-group has-success">
  139. <input id="btn-input" name="search" type="text" class="form-control input-md" placeholder="Please type the ID number of the user you want to update..." />
  140. <span class="input-group-btn">
  141. <button class="btn btn-success btn-md" id="btn-chat" type="submit">Search</button>
  142. </span>
  143. </div>
  144. </form>
  145.  
  146. <div id="respond"></div>
  147.  
  148. <?php
  149.  
  150. $conn = mysqli_connect("localhost", "root", "", "asset_inventory");
  151. if($conn === false){
  152. die("ERROR: Could not connect. " . mysqli_connect_error());
  153. }
  154.  
  155. $search = $_POST['search'];
  156. //$query_user = mysqli_query($conn,"SELECT * FROM users WHERE user_id='$search'");
  157. $query_user = mysqli_query($conn,"SELECT * FROM users WHERE user_id LIKE '%$search%' ");
  158. $row_user = mysqli_fetch_assoc($query_user);
  159. $totalRows_user = mysqli_num_rows($query_user);
  160.  
  161. ?>
  162.  
  163. <table class="table">
  164. <thead>
  165. <tr>
  166. <th>Username</th><th>User pass</th><th>User type</th>
  167. </tr>
  168. </thead>
  169. <tbody>
  170. <?php do { ?>
  171. <tr>
  172. <td><?php echo $row_user['user_name']; ?></td>
  173. <td><?php echo $row_user['user_pass']; ?></td>
  174. <td><?php echo $row_user['user_type']; ?></td>
  175. </tr>
  176. <?php } while ($row_user = mysqli_fetch_assoc($query_user)); ?>
  177. </tbody>
  178. </table>
  179.  
  180. <?php if ($totalRows_user == 0) { // Show if record empty ?>
  181.  
  182. <div class="alert alert-info" role="alert"> No record found </div>
  183.  
  184. <?php } // Show if recordset empty ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement