Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  5. </head>
  6. <style>
  7. .error {color: #FF0000;}
  8. </style>
  9. <body>
  10.  
  11. <h1>This is H1</h1>
  12.  
  13. <?php
  14.  
  15. $servername = "xxx";
  16. $username = "xxx";
  17. $password = xxx;
  18.  
  19. // Create connection
  20. $conn = new mysqli($servername, $username, $password);
  21.  
  22. // Check connection
  23. if ($conn->connect_error) {
  24. die("Connection failed: " . $conn->connect_error);
  25. }
  26.  
  27. ?>
  28.  
  29. <?php
  30. $search = $searchErr = "";
  31.  
  32. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  33. if (empty($_POST["search"])) {
  34. $searchErr = "Search keyword is required";
  35. }
  36. else {
  37. $search = test_input($_POST["search"]);
  38. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  39. $nameErr = "Only letters and white space allowed";}
  40. }
  41. }
  42.  
  43. function test_input($data) {
  44. $data = trim($data);
  45. $data = stripslashes($data);
  46. $data = htmlspecialchars($data);
  47. return $data;
  48. }
  49. ?>
  50.  
  51. <h2>Search Keyword</h2>
  52. <p><span class="error">* required field.</span></p>
  53. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  54. Search: <input type="text" name="search" value="<?php echo $search;?>">
  55. <span class="error">* <?php echo $searchErr;?></span>
  56. <br><br>
  57. <input type="submit" name="submit" value="Submit"> </form>
  58.  
  59. <?php
  60. echo '<h2> Search Result: </h2>';
  61. $searchSQL = "
  62. SELECT table_name FROM information_schema.tables
  63. WHERE LOWER(table_name) LIKE LOWER('%$search%') AND table_schema = 'xxx'";
  64.  
  65. $result = $conn->query($searchSQL);
  66.  
  67. echo '<form method="POST" action="show_columns.php">'; // opening form tag
  68.  
  69. if ($result->num_rows > 0) {
  70. // output data of each row
  71. while($row = $result->fetch_assoc()) {
  72. $table_name = $row['table_name'];
  73. echo "<input type='submit' name='table_name' value='$table_name' /> <br/>";
  74. }
  75. } else {
  76. echo ' ';
  77. }
  78.  
  79. echo '</form>'; // closing form tag
  80. ?>
  81.  
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement